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

Skip to content

TypeError when using accuracy_score as scoring argument in LogisticRegressionCV #8333

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
vivekk0903 opened this issue Feb 10, 2017 · 8 comments

Comments

@vivekk0903
Copy link
Contributor

vivekk0903 commented Feb 10, 2017

Description

TypeError: Expected sequence or array-like, got estimator

Steps/Code to Reproduce

Example:

import numpy as np
from sklearn.metrics import accuracy_score
from sklearn.linear_model import LogisticRegressionCV

X=np.random.rand(50,5)
y=np.random.randint(2, size=50)
logmodel = LogisticRegressionCV(Cs =1, dual=False , scoring = accuracy_score, penalty = 'l2')
logmodel.fit(X, y)

Expected Results

No error is thrown.

Actual Results

TypeError: Expected sequence or array-like, got estimator

Observation:

Passing 'accuracy' or make_scorer(accuracy_score) works correctly. If this is the intended behaviour it should be mentioned in documentation.
Documentation says "Scoring function to use as cross-validation criteria. For a list of scoring functions that can be used, look at sklearn.metrics. The default scoring option used is accuracy_score.". So user may be tempted to pass accuracy_score as argument which throws the error.

Suggestion

If it is the intended behaviour, then please make the documentation same as GridSearchCV, so that the confusion may be avoided
"A string (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y). If None, the score method of the estimator is used"

Versions

Linux-3.16.0-77-generic-x86_64-with-Ubuntu-14.04-trusty
('Python', '2.7.6 (default, Oct 26 2016, 20:30:19) \n[GCC 4.8.4]')
('NumPy', '1.12.0')
('SciPy', '0.18.1')
('Scikit-Learn', '0.18.1')

@jnothman
Copy link
Member

Please offer a PR providing consistency with grid search

@vivekk0903
Copy link
Contributor Author

vivekk0903 commented Feb 13, 2017

Whats PR? Ok got it Pull Request. :p
So I should do a PR on the documentation of LogisticRegressionCV?

@jnothman
Copy link
Member

jnothman commented Feb 13, 2017 via email

@vivekk0903
Copy link
Contributor Author

Yes, I have done a pull request above to update the documentation
#8346

@jnothman
Copy link
Member

Fixed in #8346. In the future, please write something like "Fixed #8333" in the description of the pull request.

jnothman pushed a commit that referenced this issue Feb 13, 2017
Updated documentation for scoring parameter of LogisticRegressionCV to make it consistent with GridSearchCV documentation. Fixes #8333
@vivekk0903
Copy link
Contributor Author

Yes, sure. Actually I am new to all this. I'll definitely keep this in mind.

sergeyf pushed a commit to sergeyf/scikit-learn that referenced this issue Feb 28, 2017
Updated documentation for scoring parameter of LogisticRegressionCV to make it consistent with GridSearchCV documentation. Fixes scikit-learn#8333
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this issue Jun 14, 2017
Updated documentation for scoring parameter of LogisticRegressionCV to make it consistent with GridSearchCV documentation. Fixes scikit-learn#8333
NelleV pushed a commit to NelleV/scikit-learn that referenced this issue Aug 11, 2017
Updated documentation for scoring parameter of LogisticRegressionCV to make it consistent with GridSearchCV documentation. Fixes scikit-learn#8333
paulha pushed a commit to paulha/scikit-learn that referenced this issue Aug 19, 2017
Updated documentation for scoring parameter of LogisticRegressionCV to make it consistent with GridSearchCV documentation. Fixes scikit-learn#8333
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this issue Nov 15, 2017
Updated documentation for scoring parameter of LogisticRegressionCV to make it consistent with GridSearchCV documentation. Fixes scikit-learn#8333
@soumyawizard
Copy link

Expected array-like (array or non-string sequence), got None

That error i am getting when executing dt_grid_estimator.score(X_train). Kindly let us help where is the gap.

@vivekk0903
Copy link
Contributor Author

@soumyawizard
Please always provide a reproducible example when reporting an error. What kind of estimator is it? For classifiers, score() requires two values, X and y which you are not supplying.

Anyways for general usage related tasks, please first submit it on Stack-Overflow instead:

lemonlaug pushed a commit to lemonlaug/scikit-learn that referenced this issue Jan 6, 2021
Updated documentation for scoring parameter of LogisticRegressionCV to make it consistent with GridSearchCV documentation. Fixes scikit-learn#8333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants