f_score_at_k_points

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

Compute the F-score at k based on single points.

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

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.