AreaUnderPR

class dtaianomaly.evaluation.AreaUnderPR[source]

Computes the Area Under the Precision-Recall Curve (AUC-PR) score.

The AUC-PR is a performance metric that is especially useful for evaluating models in imbalanced datasets, such as anomaly detection, where the number of normal instances vastly outnumbers the anomalies. The Precision-Recall curve plots precision against recall at various thresholds, providing a detailed view of the trade-off between detecting true anomalies (recall) and minimizing false alarms (precision). AUC-PR summarizes the curve into a single value, representing the overall ability of the model to identify anomalies while keeping false positives in check. A higher AUC-PR value indicates better performance, meaning the model is effective at detecting true anomalies with fewer false positives.

See also

AreaUnderROC

Compute the Area Under the ROC-Curve.

Examples

>>> from dtaianomaly.evaluation import AreaUnderPR
>>> metric = AreaUnderPR()
>>> y_true = [0, 0, 0, 1, 1, 0, 0, 0]
>>> y_pred = [1, 0, 0, 1, 1, 1, 0, 0]
>>> metric.compute(y_true, y_pred)
0.75
compute(y_true: ndarray, y_pred: ndarray, **kwargs) float

Compute the performance score.

Evaluate how closely the given anomaly scores align to the ground truth anomaly scores.

Parameters:
y_truearray-like of shape (n_samples)

Ground-truth labels.

y_predarray-like of shape (n_samples)

Predicted anomaly scores.

**kwargs

Additional arguments used for computing the evaluation metric.

Returns:
float

The alignment score of the given ground truth and prediction, according to this score.

Raises:
ValueError

When inputs are not numeric “array-like”s

ValueError

If shapes of y_true and y_pred are not of identical shape

ValueError

If y_true is non-binary.