BaselineShift#

class chemotools.augmentation.BaselineShift(scale: float = 0.0, random_state: int | None = None)[source]

Bases: TransformerMixin, OneToOneFeatureMixin, BaseEstimator

Adds a constant baseline to the data. The baseline is drawn from a one-sided uniform distribution between 0 and 0 + scale.

Parameters:
  • scale (float, default=0.0) – Range of the uniform distribution to draw the baseline factor from.

  • random_state (int, default=None) – The random state to use for the random number generator.

Variables:

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

Examples

>>> from chemotools.augmentation import BaselineShift
>>> from chemotools.datasets import load_fermentation_train
>>> # Load sample data
>>> X, _ = load_fermentation_train()
>>> # Instantiate the transformer
>>> transformer = BaselineShift(scale=0.1)
BaselineShift()
>>> transformer.fit(X)
>>> # Generate baseline-shifted data
>>> X_shifted = transformer.transform(X)
fit(X: ndarray, y=None) BaselineShift[source]

Fit the transformer to the input data.

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

  • y (None) – Ignored.

Returns:

self – The fitted transformer.

Return type:

BaselineShift

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

Transform the input data by adding a baseline to the spectrum.

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

  • y (None) – Ignored.

Returns:

X_transformed – The transformed data.

Return type:

np.ndarray of shape (n_samples, n_features)