MultiplicativeScatterCorrection#
- class chemotools.scatter.MultiplicativeScatterCorrection(method: Literal['mean', 'median'] = 'mean', reference: ndarray | None = None, weights: ndarray | None = None)[source]
Bases:
TransformerMixin,OneToOneFeatureMixin,BaseEstimatorMultiplicative scatter correction (MSC) is a preprocessing technique for removing scatter effects from spectra. It is based on fitting a linear regression model to the spectrum using a reference spectrum. The reference spectrum is usually a mean or median spectrum of a set of spectra.
- Parameters:
reference (np.ndarray of shape (n_freatures), optional, default=None) – The reference spectrum to use for the correction. If None, the mean spectrum will be used. The default is None.
use_mean (bool, optional, default=True) – Whether to use the mean spectrum as the reference. The default is True.
use_median (bool, optional, default=False) – Whether to use the median spectrum as the reference. The default is False.
- Variables:
n_features_in (int) – The number of features in the training data.
reference (np.ndarray) – The reference spectrum used for the correction.
- Raises:
ValueError – If no reference is provided.
References
- [1] Åsmund Rinnan, Frans van den Berg, Søren Balling Engelsen,
“Review of the most common pre-processing techniques for near-infrared spectra,” TrAC Trends in Analytical Chemistry 28 (10) 1201-1222 (2009).
Examples
>>> from chemotools.datasets import load_fermentation_train >>> from chemotools.scatter import MultiplicativeScatterCorrection >>> # Load sample data >>> X, _ = load_fermentation_train() >>> # Initialize MultiplicativeScatterCorrection >>> msc = MultiplicativeScatterCorrection() MultiplicativeScatterCorrection() >>> # Fit and transform the data >>> X_scaled = msc.fit_transform(X)
Attributes
ALLOWED_METHODS- ALLOWED_METHODS = ['mean', 'median']
- fit(X: ndarray, y=None) MultiplicativeScatterCorrection[source]
Fit the transformer to the input data. If no reference is provided, the mean or median spectrum will be calculated from the input data.
- Parameters:
X (np.ndarray of shape (n_samples, n_features)) – The input data to fit the transformer to.
y (None) – Ignored to align with API.
- Returns:
self – The fitted transformer.
- Return type:
MultiplicativeScatterCorrection
- transform(X: ndarray, y=None) ndarray[source]
Transform the input data by applying the multiplicative scatter correction.
- 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)