EventWiseFBeta

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

Compute the Event-Wise \(F_\beta\) score [9].

The \(F_\beta\) combines both precision and recall into a single value. It provides a balanced evaluation of a model’s performance, especially in anomaly detection, where there is often a trade-off between catching all anomalies (high recall) and minimizing false alarms (high precision). The parameter \(\beta\) controls the balance between precision and recall. A \(\beta > 1\) gives more weight to recall, useful when missing anomalies is costly, while \(\beta < 1\) emphasizes precision, reducing false positives.

The \(F_\beta\) score is the harmonic mean of the Event-Wise Precision and Event-Wise Recall.

Parameters:
betaint, float, default=1

Desired beta parameter.

See also

EventWisePrecision

Compute the event-wise Precision score.

EventWiseRecall

Compute the event-wise Recall score.

Examples

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