Thanks to visit codestin.com
Credit goes to github.com

Skip to content

LogisticRegressionCV fails when labels are strings #5868

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

Closed
dan-vine opened this issue Nov 17, 2015 · 4 comments
Closed

LogisticRegressionCV fails when labels are strings #5868

dan-vine opened this issue Nov 17, 2015 · 4 comments
Labels
Easy Well-defined and straightforward way to resolve Enhancement

Comments

@dan-vine
Copy link

While LogisticRegression can handle string labels, LogisticRegressionCV fails when labels are strings with ValueError: could not convert string to float
I guess the problem comes from calling
y_test = check_array(y_test, dtype=np.float64, ensure_2d=False)
within function _log_reg_scoring_path in file logistic.py

@GaelVaroquaux GaelVaroquaux added Easy Well-defined and straightforward way to resolve Enhancement Need Contributor labels Nov 17, 2015
@mth4saurabh
Copy link
Contributor

I think the error is in old version. I successfully recreated the error with the old version of scikit I had, I then updated it and I am not getting the error anymore, thoughts?

@raghavrv
Copy link
Member

I also confirm that it is no longer a problem @ master... @GaelVaroquaux can be closed...

@dan-vine
Copy link
Author

setting multi_class='multinomial' it fails also on master for me. Check the following example

from sklearn.linear_model import LogisticRegressionCV
import numpy as np

n_samples, n_features = 50, 5
rng = np.random.RandomState(0)
X_ref = rng.randn(n_samples, n_features)
y = rng.choice(['foo', 'bar', 'baz'], n_samples)
X_ref -= X_ref.mean()
X_ref /= X_ref.std()
lr_cv = LogisticRegressionCV(Cs=[1.], fit_intercept=False, multi_class='multinomial')
lr_cv.fit(X_ref, y)

@raghavrv
Copy link
Member

Ermm... sorry for suggesting to close this issue... the label encoder was not properly used... fix at #5874

@agramfort agramfort reopened this Nov 23, 2015
r0fls added a commit to r0fls/scikit-learn that referenced this issue Dec 2, 2015
…n#5868)

Can we just make a simple change like this? It works with @dan-vine's example this way. If yes, should we add some tests for it?

Thanks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy Well-defined and straightforward way to resolve Enhancement
Projects
None yet
Development

No branches or pull requests

6 participants