pysad.transform.preprocessing.ModifiedSTLResidualTransformer

class pysad.transform.preprocessing.ModifiedSTLResidualTransformer(period, window_size=None, robust=True, **stl_kwargs)[source]

Modified STL residual transformer used by S-ESD and S-H-ESD.

The transformer follows the residual construction in [BHVK17]: estimate the seasonal component with STL, replace STL’s trend component with the median of the raw series, and return X - seasonal - median(X). It owns only the paper’s residual step; use pysad.models.SeasonalESD or pysad.models.SeasonalHybridESD for the full detector.

Parameters:
  • period (int) – Number of observations in one seasonal period.

  • window_size (int) – Number of recent observations used for partial transforms.

  • robust (bool) – Whether to use robust STL fitting. (Default=True).

  • **stl_kwargs – Additional keyword arguments passed to statsmodels.tsa.seasonal.STL.

Methods

__init__(period[, window_size, robust])

fit(X)

Shortcut method that iteratively applies fit_partial to all instances in order.

fit_partial(X)

Fits the next timestep by adding it to the residual window.

fit_transform(X)

Shortcut method that iteratively applies fit_transform_partial to all instances in order.

fit_transform_partial(X)

Adds and transforms the next timestep without adding it twice.

transform(X)

Shortcut method that iteratively applies transform_partial to all instances in order.

transform_partial(X)

Returns the latest residual for the next candidate window.

transform_window(X)

Transforms a full window into modified STL residuals.

fit(X)

Shortcut method that iteratively applies fit_partial to all instances in order.

Parameters:

X (np.float64 array of shape (num_instances, num_features)) – Input feature vectors.

Returns:

The fitted transformer

Return type:

object

fit_partial(X)[source]

Fits the next timestep by adding it to the residual window.

fit_transform(X)

Shortcut method that iteratively applies fit_transform_partial to all instances in order.

Parameters:

X (np.float64 array of shape (num_instances, num_components)) – Input feature vectors.

Returns:

Projected feature vectors.

Return type:

np.float64 array of shape (num_instances, num_components)

fit_transform_partial(X)[source]

Adds and transforms the next timestep without adding it twice.

transform(X)

Shortcut method that iteratively applies transform_partial to all instances in order.

Parameters:

X (np.float64 array of shape (num_instances, num_features)) – Input feature vectors.

Returns:

Projected feature vectors.

Return type:

np.float64 array of shape (num_instances, num_components)

transform_partial(X)[source]

Returns the latest residual for the next candidate window.

transform_window(X)[source]

Transforms a full window into modified STL residuals.

Parameters:

X (np.float64 array of shape (num_instances,) – (num_instances, 1)): Window of univariate values.

Returns:

Modified STL residuals.

Return type:

residual_X (np.float64 array of shape (num_instances,))