Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VotingClassifier - Issue with weights #7983

sofcalca opened this issue Dec 5, 2016 · 4 comments

VotingClassifier - Issue with weights #7983

sofcalca opened this issue Dec 5, 2016 · 4 comments


Copy link

@sofcalca sofcalca commented Dec 5, 2016


ValueError when using an array for setting weights (it works with list)

Steps/Code to Reproduce

from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier as RFC
from sklearn.neighbors import KNeighborsClassifier as KNC
from sklearn.ensemble import VotingClassifier as VC
import numpy as np

X, y = load_iris(return_X_y=True)
models=[('knc', KNC()),('rnc', KNC())]
vc = VC(estimators=models, weights=weights),y)

Actual Results

ValueError                                Traceback (most recent call last)
<ipython-input-6-cc5618b5c2ae> in <module>()
      9 weights=np.array((1,2))
     10 vc = VC(estimators=models, weights=weights)
---> 11,y)

    142                                  ' tuples')
--> 144         if self.weights and len(self.weights) != len(self.estimators):
    145             raise ValueError('Number of classifiers and weights must be equal'
    146                              '; got %d weights, %d estimators'

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()


('Python', '2.7.11 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:58:36) [MSC v.1500 64 bit (AMD64)]')
('NumPy', '1.11.0')
('SciPy', '0.17.1')
('Scikit-Learn', '0.18')

Copy link

@amueller amueller commented Dec 5, 2016

should be if self.weights is not None and ...

Copy link

@vincentpham1991 vincentpham1991 commented Dec 6, 2016

I would like to contribute

Copy link

@jnothman jnothman commented Dec 6, 2016

Copy link

@vincentpham1991 vincentpham1991 commented Dec 6, 2016

@jnothman I added a patch as well as a test. Please review and let me know if any other changes should be made, or if I am not following any guidelines correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.