NonNegative#

class chemotools.baseline.NonNegative(mode: Literal['zero', 'abs'] = 'zero')[源代码]

基类:TransformerMixin, OneToOneFeatureMixin, BaseEstimator

A transformer that sets all negative values to zero or to abs.

参数:

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.

变量:

n_features_in (int) -- The number of features in the input data.

示例

>>> 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[源代码]

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 to align with API.

返回:

self -- The fitted transformer.

返回类型:

NonNegative

transform(X: ndarray, y=None) ndarray[源代码]

Transform the input data to non-negative values.

参数:
  • X (np.ndarray of shape (n_samples, n_features)) -- The input data to transform.

  • y (None) -- Ignored to align with API.

返回:

X_transformed -- The transformed data.

返回类型:

np.ndarray of shape (n_samples, n_features)