EventWisePrecision
- class dtaianomaly.evaluation.EventWisePrecision[source]
Compute the Event-Wise Precision score [9].
Precision measures how accurately the model identifies anomalies. For the Event-Wise Precision, the true and false positives are considered at the event-level:
\(TP_e\): the number of ground truth anomalous events that fully or partially overlap with a detected segment.
\(FP_e\): the number of detected segments that do not overlap with any ground truth anomalous event.
The precision is corrected by the false-alarm rate (FAR) to avoid a model which predicts all observations as anomalous to have a high score. The FAR is computed on the point-level:
\(FP\): the number of detected anomalous points that are not actually anomalous.
We then compute the Event-Wise Precision as (with \(N\): the total number of normal points):
\[\text{Event-Wise Precision} = \frac{TP_e}{TP_e + FP_e} \times (1 - \frac{FP}{N})\]See also
EventWiseRecallCompute the event-wise Recall score.
EventWiseFBetaCompute the event-wise \(F_\beta\) score.
Examples
>>> from dtaianomaly.evaluation import EventWisePrecision >>> metric = EventWisePrecision() >>> 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.333...
- 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.