AffiliationFBeta

class dtaianomaly.evaluation.AffiliationFBeta(beta: float | int = 1)[source]

Compute the affiliation-based \(F_\beta\) score [17].

The affiliation-metrics will first divide the time domain into a number of so-called affiliations: subsequences that are closest to the ground truth anomaly events. These affiliations do not have a fixed size. The precision is computed as the distance of the predicted anomalies to the ground truth event, and the recall is computed as the distance of the ground truth anomaly to the predicted anomalies. These precision and recall scores within each affiliation is then averaged. The \(F_\beta\) score is the harmonic mean of this average precision and recall.

Parameters:
betaint, float, default=1

Desired beta parameter.

See also

AffiliationPrecision

Compute the affiliation-based Precision score.

AffiliationRecall

Compute the affiliation-based Recall score.

Examples

>>> from dtaianomaly.evaluation import AffiliationFBeta
>>> metric = AffiliationFBeta()
>>> 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.814...
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.

ValueError

If y_pred is non-binary.