IndexShift#

class chemotools.augmentation.IndexShift(shift: int = 0, padding_mode: Literal['zeros', 'constant', 'wrap', 'extend', 'mirror', 'linear'] = 'linear', pad_value: float = 0.0, random_state: int | None = None)[ソース]

ベースクラス: TransformerMixin, OneToOneFeatureMixin, BaseEstimator

Shift the spectrum a given number of indices between -shift and +shift drawn from a discrete uniform distribution.

パラメータ:
  • shift (int, default=0) -- Maximum number of indices by which the data is randomly shifted. The actual shift is a random integer between -shift and shift (inclusive).

  • padding_mode ({'zeros', 'constant', 'wrap', 'extend',) --

    'mirror', 'linear'}, default='linear' Specifies how to handle padding when shifting the data:

    • 'zeros': Pads with zeros.

    • 'constant': Pads with a constant value defined by pad_value.

    • 'wrap': Circular shift (wraps around).

    • 'extend': Extends using edge values.

    • 'mirror': Mirrors the signal.

    • 'linear': Uses linear regression to extrapolate values.

  • pad_value (float, default=0.0) -- The value used for padding when padding_mode='constant'.

  • random_state (int, optional, default=None) -- The random seed for reproducibility.

変数:

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

サンプル

>>> from chemotools.augmentation import IndexShift
>>> from chemotools.datasets import load_fermentation_train
>>> # Load sample data
>>> X, _ = load_fermentation_train()
>>> # Instantiate the transformer
>>> transformer = IndexShift(shift=2, padding_mode="constant",)
IndexShift()
>>> transformer.fit(X)
>>> # Generate shifted data
>>> X_shifted = transformer.transform(X)
fit(X: ndarray, y=None) IndexShift[ソース]

Fit the transformer to the input data.

パラメータ:
  • X (np.ndarray of shape (n_samples, n_features)) -- The input data to fit the transformer to.

  • y (None) -- Ignored.

戻り値:

self -- The fitted transformer.

戻り値の型:

IndexShift

transform(X: ndarray, y=None) ndarray[ソース]

Transform the input data by shifting the spectrum.

パラメータ:
  • X (np.ndarray of shape (n_samples, n_features)) -- The input data to transform.

  • y (None) -- Ignored.

戻り値:

X_transformed -- The transformed data with the applied shifts.

戻り値の型:

np.ndarray of shape (n_samples, n_features)