alibi_detect.od.sr module¶
-
class
alibi_detect.od.sr.
SpectralResidual
(threshold=None, window_amp=None, window_local=None, n_est_points=None, n_grad_points=5)[source]¶ Bases:
alibi_detect.base.BaseDetector
,alibi_detect.base.ThresholdMixin
-
__init__
(threshold=None, window_amp=None, window_local=None, n_est_points=None, n_grad_points=5)[source]¶ Outlier detector for time-series data using the spectral residual algorithm. Based on “Time-Series Anomaly Detection Service at Microsoft” (Ren et al., 2019) https://arxiv.org/abs/1906.03821
- Parameters
threshold (
Optional
[float
]) – Threshold used to classify outliers. Relative saliency map distance from the moving average.window_amp (
Optional
[int
]) – Window for the average log amplitude.window_local (
Optional
[int
]) – Window for the local average of the saliency map.n_est_points (
Optional
[int
]) – Number of estimated points padded to the end of the sequence.n_grad_points (
int
) – Number of points used for the gradient estimation of the additional points padded to the end of the sequence.
- Return type
None
-
add_est_points
(X, t)[source]¶ Pad the time series with additional points since the method works better if the anomaly point is towards the center of the sliding window.
- Parameters
X (numpy.ndarray) – Time series of instances.
t (numpy.ndarray) – Time steps.
- Return type
numpy.ndarray
- Returns
Padded version of X.
-
compute_grads
(X, t)[source]¶ Slope of the straight line between different points of the time series multiplied by the average time step size.
- Parameters
X (numpy.ndarray) – Time series of instances.
t (numpy.ndarray) – Time steps.
- Return type
numpy.ndarray
- Returns
Array with slope values.
-
infer_threshold
(X, t=None, threshold_perc=95.0)[source]¶ Update threshold by a value inferred from the percentage of instances considered to be outliers in a sample of the dataset.
- Parameters
X (numpy.ndarray) – Batch of instances.
threshold_perc (
float
) – Percentage of X considered to be normal based on the outlier score.
- Return type
None
-
predict
(X, t=None, return_instance_score=True)[source]¶ Compute outlier scores and transform into outlier predictions.
- Parameters
- Return type
- Returns
Dictionary containing ‘meta’ and ‘data’ dictionaries.
’meta’ has the model’s metadata.
’data’ contains the outlier predictions and instance level outlier scores.
-