NonNegative#
- class chemotools.baseline.NonNegative(mode: Literal['zero', 'abs'] = 'zero')[source]
Bases:
TransformerMixin,OneToOneFeatureMixin,BaseEstimatorA transformer that sets all negative values to zero or to abs.
- Parameters:
mode (Literal["zero", "abs"], optional, default="zero") – The mode to use for the non-negative values. Can be: - zero: set all negative values to zero. - abs: set all negative values to their absolute value.
- Variables:
n_features_in (int) – The number of features in the input data.
Examples
>>> from chemotools.baseline import NonNegative >>> from chemotools.datasets import load_fermentation_train >>> # Load sample data >>> X, _ = load_fermentation_train() >>> # Instantiate the transformer >>> transformer = NonNegative(mode="zero") NonNegative(mode="zero") >>> transformer.fit(X) >>> # Generate non-negative data >>> X_non_negative = transformer.transform(X)
- fit(X: ndarray, y=None) NonNegative[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:
NonNegative
- transform(X: ndarray, y=None) ndarray[source]
Transform the input data to non-negative values.
- 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)