PolynomialCorrection#
- class chemotools.baseline.PolynomialCorrection(order: int = 1, indices: list | None = None)[source]
Bases:
TransformerMixin,OneToOneFeatureMixin,BaseEstimatorA transformer that subtracts a polynomial baseline from the input data. The polynomial is fitted to the points in the spectrum specified by the indices parameter.
- Parameters:
order (int, optional, default=1) – The order of the polynomial to fit to the baseline. Defaults to 1.
indices (list, optional, default=None) – The indices of the points in the spectrum to fit the polynomial to. Defaults to None, which fits the polynomial to all points in the spectrum (equivalent to detrend).
- Variables:
Examples
>>> from chemotools.baseline import PolynomialCorrection >>> from chemotools.datasets import load_fermentation_train >>> # Load sample data >>> X, _ = load_fermentation_train() >>> # Instantiate the transformer >>> transformer = PolynomialCorrection(order=2, indices=[0, 100, 200, 300, 400, 500]) PolynomialCorrection() >>> transformer.fit(X) >>> # Generate baseline-corrected data >>> X_corrected = transformer.transform(X)
- fit(X: ndarray, y=None) PolynomialCorrection[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 to align with API.
- Returns:
self – The fitted transformer.
- Return type:
PolynomialCorrection
- transform(X: ndarray, y=None) ndarray[source]
Transform the input data by subtracting the polynomial baseline.
- 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)