Classifiers Module

The classifiers module provides classes for time series classification and pattern recognition.

class tide.classifiers.STLEDetector(period='24h', trend='15d', absolute_threshold=100, seasonal=None, stl_kwargs=None)[source]

Bases: ClassifierMixin, BaseSTL

A custom anomaly detection model based on statsmodel STL (Seasonal and Trend decomposition using Loess).

The STL decomposition breaks down time series into three components: trend, seasonal, and residual. This class uses the residual component to detect anomalies based on the absolute threshold (absolute value of residual exceed threshold).

See statsmodel doc for additional STL configuration. (https://www.statsmodels.org/stable/index.html)

Parameters:
  • period (int | str | dt.timedelta) – The period of the time series (e.g., daily, weekly, monthly, etc.). Can be an integer, string, or timedelta. This defines the seasonal periodicity for the STL decomposition.

  • absolute_threshold (int | float) – The threshold value for residuals. Any residuals exceeding this threshold are considered anomalies.

  • trend (int | str | dt.timedelta, optional) – The length of the trend smoother. Must be odd and larger than season Statsplot indicate it is usually around 150% of season. Strongly depends on your time series.

  • seasonal (int | str | dt.timedelta, optional) – The seasonal component’s smoothing parameter for STL. It defines how much the seasonal component is smoothed. If given as an integer, it must be an odd number. If None, a default value will be used.

  • stl_kwargs (dict[str, float], optional) – Additional keyword arguments for the STL decomposition. These allow fine-tuning of the decomposition process. (https://www.statsmodels.org/stable/index.html)

Variables:
  • labels (pd.DataFrame) – A DataFrame with binary labels (0 or 1), indicating whether an anomaly is detected (1) or not (0).

  • stl_res (dict) – A dictionary that holds the fitted STL results for each feature in the dataset.

__sklearn_is_fitted__():

Checks whether the model has been fitted and returns a boolean indicating the fitted status.

fit(X: pd.Series | pd.DataFrame):

Fits the STL model to the input time series data. Computes and stores residuals for each column in X.

predict(X: pd.Series | pd.DataFrame):

Fits the model and predicts anomalies by comparing the residuals with the absolute threshold. Returns a 0-1 Pandas DataFrame

Raises:

ValueError – If the seasonal parameter is an even number when passed as an integer.

__init__(period='24h', trend='15d', absolute_threshold=100, seasonal=None, stl_kwargs=None)[source]
fit(X, y=None)[source]
predict(X)[source]