FixedCutoffThreshold
- class dtaianomaly.thresholding.FixedCutoffThreshold(cutoff: float)[source]
Thresholding based on a fixed cut-off.
Values higher than the cut-off are considered anomalous (1), values below the cut-off are considered normal (0).
- Parameters:
- cutofffloat
The cutoff above which the given anomaly scores indicate an anomaly.
Examples
>>> from dtaianomaly.thresholding import FixedCutoffThreshold >>> thresholder = FixedCutoffThreshold(0.7) >>> thresholder.threshold([0.1, 0.2, 0.3, 0.6, 0.8, 0.5, 0.3, 0.3]) array([0, 0, 0, 0, 1, 0, 0, 0])
- threshold(scores: ndarray) ndarray
Threshold the given anomaly scores.
Apply the thresholding operation to the given anomaly scores. This function will perform the necessary checks and formatting on the anomaly scores, before effectively applying the thresholding.
- Parameters:
- scoresarray-like of shape (n_samples)
The continuous anomaly scores to convert to binary anomaly labels.
- Returns:
- array-like of shape (n_samples)
The discrete anomaly labels, in which a 0 indicates normal and a 1 indicates anomalous.
- Raises:
- ValueError
If scores is not a valid array
- ValueError
If scores is not one-dimensional. If all dimensions but one have a size of 1, then no error will be thrown.