average_precision_score
¶
average_precision_score(labels: ArrayLike, scores: ArrayLike) -> float
Average precision of binary labels ranked by scores.
\[
\text{AP} = \sum_n (R_n - R_{n-1}) P_n
\]
where \(P_n\) and \(R_n\) are the precision and recall at the
\(n\)-th distinct score threshold, as in scikit-learn's
average_precision_score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
ArrayLike
|
Binary ground truth ( |
required |
scores
|
ArrayLike
|
Scores of the samples (higher means more likely positive),
shape |
required |
Returns:
| Type | Description |
|---|---|
float
|
The average precision, between 0 and 1. |
Example:
from mlx_graphs.metrics import average_precision_score
average_precision_score(mx.array([1, 0, 1, 0]),
mx.array([0.9, 0.1, 0.4, 0.5]))
>>> 0.8333
Source code in mlx_graphs/metrics/functional.py
from mlx_graphs.metrics import average_precision_score · mlx_graphs/metrics/functional.py