Interquartile Range (IQR) Detector¶
Flags anomalies that are beyond the IQR (between the third and the first quartile) of historical data by some factor of it’s difference (typically 1.5). This is similar to a threshold-based detector, but the thresholds are computed as distances from the IQR of historical data when the detector is fitted.
- class darts.ad.detectors.iqr_detector.IQRDetector(scale=1.5)[source]¶
Bases:
QuantileDetector
IQR Detector
Flags values that lie outside of the interquartile range (IQR) by more than a certain factor of IQR’s value as anomalies. The factor is passed in the scale parameter.
If a single value is provided for scale, this same value will be used across all components of the series.
If a sequences of values is given for the scale parameter, it’s length must match the dimensionality of the series passed.
- Parameters
scale (
Union
[Sequence
[float
],float
]) – (Sequence of) scale(s) used to indicate what distance from the IQR constitutes an anomaly. Defaults to 1.5. Must be non-negative. If a sequence, must match the dimensionality of the series this detector is applied to.
Attributes
high_threshold
low_threshold
Methods
detect
(series[, name])Detect anomalies on given time series.
eval_metric
(anomalies, pred_scores[, ...])Score the results against true anomalies.
fit
(series)Trains the detector on the given time series.
fit_detect
(series)Trains the detector and detects anomalies on the same series.
- detect(series, name='series')¶
Detect anomalies on given time series.
- Parameters
series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – The (sequence of) series on which to detect anomalies.name (
str
) – The name of series.
- Returns
binary prediction (1 if considered as an anomaly, 0 if not)
- Return type
Union[TimeSeries, Sequence[TimeSeries]]
- eval_metric(anomalies, pred_scores, window=1, metric='recall')¶
Score the results against true anomalies.
- Parameters
anomalies (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – The (sequence of) ground truth binary anomaly series (1 if it is an anomaly and 0 if not).pred_scores (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – The (sequence of) of estimated anomaly score series indicating how anomalous each window of size w is.window (
int
) – Integer value indicating the number of past samples each point represents in the pred_scores.metric (
Literal
[‘recall’, ‘precision’, ‘f1’, ‘accuracy’]) – The name of the metric function to use. Must be one of “recall”, “precision”, “f1”, and “accuracy”. Default: “recall”.
- Returns
Metric results for each anomaly score
- Return type
Union[float, Sequence[float], Sequence[Sequence[float]]]
- fit(series)¶
Trains the detector on the given time series.
- Parameters
series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – Time (sequence of) series to be used to train the detector.- Returns
Fitted Detector.
- Return type
self
- fit_detect(series)¶
Trains the detector and detects anomalies on the same series.
- Parameters
series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – Time series to be used for training and be detected for anomalies.- Returns
Binary prediciton (1 if considered as an anomaly, 0 if not)
- Return type
Union[TimeSeries, Sequence[TimeSeries]]
- property high_threshold¶
- property low_threshold¶