etna.analysis.get_anomalies_density#
- get_anomalies_density(ts: TSDataset, in_column: str = 'target', window_size: int = 15, distance_coef: float = 3, n_neighbors: int = 3, distance_func: Literal['absolute_difference'] | Callable[[float, float], float] = 'absolute_difference', index_only: bool = True) Dict[str, List[Timestamp] | List[int] | Series] [source]#
Compute outliers according to density rule.
For each element in the series build all the windows of size
window_size
containing this point. If any of the windows contains at leastn_neighbors
that are closer thandistance_coef * std(series)
to target point according todistance_func
target point is not an outlier.- Parameters:
ts (TSDataset) – TSDataset with timeseries data
in_column (str) – name of the column in which the anomaly is searching
window_size (int) – size of windows to build
distance_coef (float) – factor for standard deviation that forms distance threshold to determine points are close to each other
n_neighbors (int) – min number of close neighbors of point not to be outlier
distance_func (Literal['absolute_difference'] | ~typing.Callable[[float, float], float]) – distance function. If a string is specified, a corresponding vectorized implementation will be used. Custom callable will be used as a scalar function, which will result in worse performance.
index_only (bool) – whether to return only outliers indices. If False will return outliers series
- Returns:
dict of outliers in format {segment: [outliers_timestamps]}
- Return type:
Notes
It is a variation of distance-based (index) outlier detection method adopted for timeseries.