Skip to content

sklearn/unknown-scoring-name

Rule unknown-scoring-name
Pack scikit-learn
Severity error
Fix none, edit by hand
Library versions every version

A scoring text that is not a scorer name raises. Pick a name from get_scorer_names(), and note that losses start with neg_.

scores = cross_val_score(model, X, y, scoring="mean_squared_error")
scores = cross_val_score(model, X, y, scoring="neg_mean_squared_error")

The rule reports scoring="mean_squared_error" and any other string that get_scorer refuses. It reads scoring in a search, cross_val_score, cross_validate and the other scikit-learn functions that take it, and the argument of get_scorer itself.

xpd has no automatic fix, so make the change by hand.

The rule checks each string against sklearn.metrics.get_scorer_names() on scikit-learn 1.9.1. scoring="mean_squared_error", scoring="log_loss" and scoring="auc" raise InvalidParameterError, and "roc_auc_score" in a list given to cross_validate raises ValueError. A string with { or % in it, or an f-string, is left alone, because code fills it in later. Recall was 16 of 32. The rule found none of 16 scoring strings or dicts of scorer names kept in a variable.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

$S is not a scorer name, so this raises. Pick a name from sklearn.metrics.get_scorer_names(). Losses carry the neg_ prefix, as in "neg_mean_squared_error".

Browse the other rules of the scikit-learn pack.