-
-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Closed
Description
Consider the case of binary classification. The average precision metrics as implemented in metrics.average_precision_score
is not symmetric for classes, so it's value depends on which class if the positive one. According to the docs, setting parameter average=None
should result in the function returning the value for both classes. However, only a single value is returned. setting average='macro'
returns only the value for the class '1'.
This seems not completely correct and expected. Is this the intended behavior? Would be nice to have some discussion on this :).
Sample:
from sklearn.datasets import make_classification
from sklearn.linear_model import RidgeClassifierCV
from sklearn.metrics import average_precision_score
from sklearn.model_selection import train_test_split
X, y = make_classification(n_samples=5000, n_informative=5, random_state=88)
X_train, X_test, y_train, y_test = train_test_split(X, y)
classer = RidgeClassifierCV(scoring='average_precision', cv=10)
classer.fit(X_train, y_train)
pred = classer.decision_function(X_test)
true = y_test
## Not symmetric for different classes, but average=None returns only one value
## average='macro' also returns the AP value for the class '1'
print(average_precision_score(true, pred, average=None))
print(average_precision_score((1-true), (1-pred), average=None))
Metadata
Metadata
Assignees
Labels
No labels