Skip to content

Commit

Permalink
[MRG+1] Issue#5803 : Regression Test added (scikit-learn#8112)
Browse files Browse the repository at this point in the history
* Issue#5803 Regression Test added

* Float predictions values used for testing

* Custom Classifier used for test
  • Loading branch information
amanp10 authored and Sundrique committed Jun 14, 2017
1 parent 50925c9 commit 4e8e2ca
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions sklearn/ensemble/tests/test_voting_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
X, y = iris.data[:, 1:3], iris.target


# A custom classifier based on SVC to return 'float' type class labels
class FaultySVC(SVC):
def predict(self, X):
return super(FaultySVC, self).predict(X).astype(float)


def test_estimator_init():
eclf = VotingClassifier(estimators=[])
msg = ('Invalid `estimators` attribute, `estimators` should be'
Expand Down Expand Up @@ -364,3 +370,16 @@ def test_estimator_weights_format():
eclf1.fit(X, y)
eclf2.fit(X, y)
assert_array_equal(eclf1.predict_proba(X), eclf2.predict_proba(X))


def test_predict_for_hard_voting():
# Test predictions array data type error
clf1 = FaultySVC(random_state=123)
clf2 = GaussianNB()
clf3 = SVC(probability=True, random_state=123)
eclf1 = VotingClassifier(estimators=[
('fsvc', clf1), ('gnb', clf2), ('svc', clf3)], weights=[1, 2, 3],
voting='hard')

eclf1.fit(X, y)
eclf1.predict(X)

0 comments on commit 4e8e2ca

Please sign in to comment.