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)[source]
Bases:
TransformerMixin,OneToOneFeatureMixin,BaseEstimatorShift the spectrum a given number of indices between -shift and +shift drawn from a discrete uniform distribution.
- Parameters:
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.
- Variables:
n_features_in (int) – The number of features in the input data.
Examples
>>> 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[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:
IndexShift
- transform(X: ndarray, y=None) ndarray[source]
Transform the input data by shifting 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 with the applied shifts.
- Return type:
np.ndarray of shape (n_samples, n_features)