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,BaseEstimatorShift 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)