votes up 5

For evaluating multiple scores, use sklearn.model_selection.cross_validate instead. (param0) was passed.

Package:
Exception Class:
ValueError

Raise code

    return None
        else:
            raise TypeError(
                "If no scoring is specified, the estimator passed should "
                "have a 'score' method. The estimator %r does not."
                % estimator)
    elif isinstance(scoring, Iterable):
        raise ValueError("For evaluating multiple scores, use "
                         "sklearn.model_selection.cross_validate instead. "
                         "{0} was passed.".format(scoring))
    else:
        raise ValueError("scoring value should either be a callable, string or"
                         " None. %r was passed" % scoring)


def _che
🙏 Scream for help to Ukraine
Today, 3rd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 1 votes down

Summary:

This exception can be thrown when calling the check_scoring function from sklearn.metrics._scorer. The function takes in an estimator that is required and it has an optional parameter for scoring. By default, this parameter is set to None. If a value is passed in for scoring, and that value is an iterable, then this exception will be thrown. Therefore, you can either leave scoring as None or you can pass in a string that is in the SCORERS dictionary. Some valid strings you can use are:

  • r2
  • max_error
  • neg_median_absolute_error
  • accuracy
  • rand_score
  • roc_auc

Passing in a value of None, or one of the valid strings will get rid of the exception.

Code to Reproduce the Error(Wrong):

from sklearn.metrics._scorer import check_scoring
import numpy as np
from sklearn.multiclass import OutputCodeClassifier
from sklearn.ensemble import RandomForestClassifier

clf = OutputCodeClassifier(
    estimator=RandomForestClassifier(random_state=0),
    random_state=0,
    code_size=1.5)
arr = np.array([1,2,3,4,5])
check_scoring(clf, scoring=arr)

Error Message:

ValueError                                Traceback (most recent call last)
<ipython-input-36-527bb45926eb> in <module>()
      9     code_size=1.5)
     10 arr = np.array([1,2,3,4,5])
---> 11 check_scoring(clf, scoring=arr)

/usr/local/lib/python3.7/dist-packages/sklearn/metrics/_scorer.py in check_scoring(estimator, scoring, allow_none)
    428         raise ValueError("For evaluating multiple scores, use "
    429                          "sklearn.model_selection.cross_validate instead. "
--> 430                          "{0} was passed.".format(scoring))
    431     else:
    432         raise ValueError("scoring value should either be a callable, string or"

ValueError: For evaluating multiple scores, use sklearn.model_selection.cross_validate instead. [1 2 3 4 5] was passed.

Working Version Using a String (Valid):

from sklearn.metrics._scorer import check_scoring
import numpy as np
from sklearn.multiclass import OutputCodeClassifier
from sklearn.ensemble import RandomForestClassifier

clf = OutputCodeClassifier(
    estimator=RandomForestClassifier(random_state=0),
    random_state=0,
    code_size=1.5)
arr = np.array([1,2,3,4,5])
check_scoring(clf, scoring='r2')

Working Version Using None (Valid):

from sklearn.metrics._scorer import check_scoring
import numpy as np
from sklearn.multiclass import OutputCodeClassifier
from sklearn.ensemble import RandomForestClassifier

clf = OutputCodeClassifier(
    estimator=RandomForestClassifier(random_state=0),
    random_state=0,
    code_size=1.5)
arr = np.array([1,2,3,4,5])
check_scoring(clf, scoring=None)
Jul 14, 2021 codingcomedyig answer

Add a possible fix

Please authorize to post fix