ThresholdMetric

class dtaianomaly.evaluation.ThresholdMetric(thresholder: Thresholding, metric: BinaryMetric)[source]

Apply a Thresholding and BinaryMetric in sequence.

Wrapper to combine a BinaryMetric object with some Thresholding, to make sure that it can take continuous anomaly scores as an input. This is done by first applying some Thresholding to the predicted anomaly scores, after which a BinaryMetric can be computed.

Parameters:
thresholderThresholding

Instance of the desired Thresholding class.

metricBinaryMetric

Instance of the desired Metric class.

Examples

>>> from dtaianomaly.evaluation import ThresholdMetric, Precision
>>> from dtaianomaly.thresholding import FixedCutoffThreshold
>>> metric = ThresholdMetric(FixedCutoffThreshold(0.9), Precision())
>>> y_true = [   0,   0,   0,   1,   1,   0,   0,   0]
>>> y_pred = [0.95, 0.5, 0.4, 0.8, 1.0, 0.7, 0.2, 0.1]
>>> 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.