check_scoring#
- sklearn.metrics.check_scoring(estimator=None, scoring=None, *, allow_none=False)[source]#
Determine scorer from user options.
A TypeError will be thrown if the estimator cannot be scored.
- Parameters:
- estimatorestimator object implementing ‘fit’ or None, default=None
The object to use to fit the data. If
None
, then this function may error depending onallow_none
.- scoringstr, callable, list, tuple, or dict, default=None
Scorer to use. If
scoring
represents a single score, one can use:a single string (see The scoring parameter: defining model evaluation rules);
a callable (see Defining your scoring strategy from metric functions) that returns a single value.
If
scoring
represents multiple scores, one can use:a list or tuple of unique strings;
a callable returning a dictionary where the keys are the metric names and the values are the metric scorers;
a dictionary with metric names as keys and callables a values.
If None, the provided estimator object’s
score
method is used.- allow_nonebool, default=False
If no scoring is specified and the estimator has no score function, we can either return None or raise an exception.
- Returns:
- scoringcallable
A scorer callable object / function with signature
scorer(estimator, X, y)
.
Examples
>>> 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...