f_score_at_k_ranges

f_score_at_k_ranges(y_true: ndarray, y_score: ndarray, k: int | None = None) float[source]

Compute the range-based F-score at k based on anomaly ranges.

This metric only considers the top-k predicted anomaly ranges within the scoring by finding a threshold on the scoring that produces at least k anomalous ranges. If k is not specified, the number of anomalies within the ground truth is used as k.

This implementation uses the community package prts as a soft-dependency to compute the range-based F-score.

Parameters:
y_truenp.ndarray

True binary labels of shape (n_instances,).

y_scorenp.ndarray

Anomaly scores for each point of the time series of shape (n_instances,).

kint (optional)

Number of top anomalies used to calculate precision. If k is not specified (None) the number of true anomalies (based on the ground truth values) is used.

Returns:
float

F1 score at k.