Skip to content

Averaging scores for classes for the average_precision_score #10564

@bartdp1

Description

@bartdp1

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions