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

Closed
sofcalca opened this Issue Dec 5, 2016 · 4 comments

Comments

Projects
None yet
5 participants
@sofcalca

sofcalca commented Dec 5, 2016

Description

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())]
weights=np.array((1,2))
vc = VC(estimators=models, weights=weights)
vc.fit(X,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 vc.fit(X,y)


    142                                  ' tuples')
    143 
--> 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()

Versions

Windows-10-10.0.14393
('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')

@amueller

This comment has been minimized.

Show comment
Hide comment
@amueller

amueller Dec 5, 2016

Member

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

Member

amueller commented Dec 5, 2016

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

@vincentpham1991

This comment has been minimized.

Show comment
Hide comment
@vincentpham1991

vincentpham1991 Dec 6, 2016

Contributor

I would like to contribute

Contributor

vincentpham1991 commented Dec 6, 2016

I would like to contribute

@jnothman

This comment has been minimized.

Show comment
Hide comment
@jnothman

jnothman Dec 6, 2016

Member
Member

jnothman commented Dec 6, 2016

@vincentpham1991

This comment has been minimized.

Show comment
Hide comment
@vincentpham1991

vincentpham1991 Dec 6, 2016

Contributor

@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.

Contributor

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.

@jnothman jnothman closed this in #7989 Dec 8, 2016

jnothman added a commit that referenced this issue Dec 8, 2016

adis300 added a commit to adis300/scikit-learn that referenced this issue Dec 13, 2016

sergeyf added a commit to sergeyf/scikit-learn that referenced this issue Feb 28, 2017

Sundrique added a commit to Sundrique/scikit-learn that referenced this issue Jun 14, 2017

NelleV added a commit to NelleV/scikit-learn that referenced this issue Aug 11, 2017

paulha added a commit to paulha/scikit-learn that referenced this issue Aug 19, 2017

maskani-moh added a commit to maskani-moh/scikit-learn that referenced this issue Nov 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment