FBeta

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

Computes the \(F_\beta\) score.

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 precision and recall. It can be expressed as:

\[F_\beta = \frac{(1 + \beta^2) \text{tp}} {(1 + \beta^2) \text{tp} + \text{fp} + \beta^2 \text{fn}}\]

A high \(F_\beta\) score indicates a good balance between detecting actual anomalies and minimizing false positives.

Parameters:
betaint, float, default=1

Desired beta parameter.

See also

Precision

Compute the Precision score.

Recall

Compute the Recall score.

Examples

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