Determine scorer from user options.
A TypeError will be thrown if the estimator cannot be scored.
The object to use to fit the data. If None, then this function may error depending on allow_none.
Scorer to use. If scoring represents a single score, one can use:
If scoring represents multiple scores, one can use:
callable(estimator, X, y).If None, the provided estimator object’s score method is used.
Whether to return None or raise an error if no scoring is specified and the estimator has no score method.
Whether to raise an exception (if a subset of the scorers in multimetric scoring fails) or to return an error code.
True, raises the failing scorer’s exception.False, a formatted string of the exception details is passed as result of the failing scorer(s).This applies if scoring is list, tuple, set, or dict. Ignored if scoring is a str or a callable.
Added in version 1.6.
A scorer callable object / function with signature scorer(estimator, X, y).
>>> from sklearn.datasets import load_iris >>> from sklearn.metrics import check_scoring >>> from sklearn.tree import DecisionTreeClassifier >>> X, y = load_iris(return_X_y=True) >>> classifier = DecisionTreeClassifier(max_depth=2).fit(X, y) >>> scorer = check_scoring(classifier, scoring='accuracy') >>> scorer(classifier, X, y) 0.96...
>>> from sklearn.metrics import make_scorer, accuracy_score, mean_squared_log_error
>>> X, y = load_iris(return_X_y=True)
>>> y *= -1
>>> clf = DecisionTreeClassifier().fit(X, y)
>>> scoring = {
... "accuracy": make_scorer(accuracy_score),
... "mean_squared_log_error": make_scorer(mean_squared_log_error),
... }
>>> scoring_call = check_scoring(estimator=clf, scoring=scoring, raise_exc=False)
>>> scores = scoring_call(clf, X, y)
>>> scores
{'accuracy': 1.0, 'mean_squared_log_error': 'Traceback ...'}
© 2007–2025 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.6/modules/generated/sklearn.metrics.check_scoring.html