Back to models
Transformer

SavitzkyGolayTransformer

Savitzky-Golay filter for smoothing or differentiating time series.

Uses local polynomial regression (convolution) to smooth data or to compute numerical derivatives, preserving features of the distribution like relative maxima and minima better than moving average approaches.

Wraps scipy.signal.savgol_filter.

Quickstart

python
from sktime.transformations.savitzky_golay import SavitzkyGolayTransformer

estimator = SavitzkyGolayTransformer(window_length=5, polyorder=2, deriv=0, delta=1.0, mode='interp', cval=0.0)

Parameters(6)

window_lengthint, default=5
Length of the filter window. Must be a positive odd integer.
polyorderint, default=2

Order of the polynomial used to fit the samples. Must be less than window_length.

derivint, default=0
Order of the derivative to compute. Use 0 to simply smooth the data without differentiation.
deltafloat, default=1.0

Spacing of the samples to which the filter will be applied. Only relevant when deriv > 0.

modestr, default=”interp”

How to extend the signal at the boundaries. One of "interp", "mirror", "nearest", "wrap", "constant".

cvalfloat, default=0.0

Value to fill past the edges of the input when mode is "constant".

Examples

>>> from sktime.transformations.savitzky_golay import (
... SavitzkyGolayTransformer,
... )
>>> from sktime.datasets import load_airline
>>> y = load_airline ()
>>> t = SavitzkyGolayTransformer (window_length = 7, polyorder = 2)
>>> y_smooth = t. fit_transform (y)