SavitzkyGolayFilter#

class chemotools.smooth.SavitzkyGolayFilter(window_size: int = 3, polynomial_order: int = 1, mode: Literal['mirror', 'constant', 'nearest', 'wrap', 'interp'] = 'nearest', axis: int = 1)[source]

Bases: _BaseFIRFilter

A transformer that calculates the Savitzky-Golay filter of the input data.

Parameters:
  • window_size (int, optional) – The size of the window to use for the Savitzky-Golay filter. Must be odd. Default is 3.

  • polynomial_order (int, optional) – The order of the polynomial to use for the Savitzky-Golay filter. Must be less than window_size. Default is 1.

  • mode (str, optional) – The mode to use for the Savitzky-Golay filter. Can be “nearest”, “constant”, “reflect”, “wrap”, “mirror” or “interp”. Default is “nearest”.

Variables:

n_features_in (int) – The number of features in the training data.

Examples

>>> from chemotools.datasets import load_fermentation_train
>>> from chemotools.smooth import SavitzkyGolayFilter
>>> # Load sample data
>>> X, _ = load_fermentation_train()
>>> # Initialize SavitzkyGolayFilter
>>> sgf = SavitzkyGolayFilter()
SavitzkyGolayFilter()
>>> # Fit and transform the data
>>> X_smoothed = sgf.fit_transform(X)
fit(X: ndarray, y: ndarray | None = None) SavitzkyGolayFilter[source]

Fit the Savitzky-Golay filter to the data.

Parameters:
  • X (np.ndarray of shape (n_samples, n_features)) – The input data to fit the transformer.

  • y (Ignored) – Not used, present for API consistency by convention.

Returns:

self – The fitted transformer.

Return type:

SavitzkyGolayFilter

transform(X: ndarray, y: ndarray | None = None) ndarray[source]

Transform the input data by applying the Savitzky-Golay filter.

Parameters:
  • X (np.ndarray of shape (n_samples, n_features)) – The input data to transform.

  • y (None) – Ignored to align with API.

Returns:

X_transformed – The transformed data.

Return type:

np.ndarray of shape (n_samples, n_features)