get_scorer#
- sklearn.metrics.get_scorer(scoring)[source]#
从字符串获取评分器。
Read more in the User Guide.
get_scorer_namescan be used to retrieve the names of all available scorers.- 参数:
- scoringstr, callable or None
Scoring method as string. If callable it is returned as is. If None, returns None.
- 返回:
- scorercallable
The scorer.
注意事项
When passed a string, this function always returns a copy of the scorer object. Calling
get_scorertwice for the same scorer results in two separate scorer objects.示例
>>> import numpy as np >>> from sklearn.dummy import DummyClassifier >>> from sklearn.metrics import get_scorer >>> X = np.reshape([0, 1, -1, -0.5, 2], (-1, 1)) >>> y = np.array([0, 1, 1, 0, 1]) >>> classifier = DummyClassifier(strategy="constant", constant=0).fit(X, y) >>> accuracy = get_scorer("accuracy") >>> accuracy(classifier, X, y) 0.4