Skip to content

TypeError when using accuracy_score as scoring argument in LogisticRegressionCV #8333

@vivekk0903

Description

@vivekk0903

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')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions