nirs4all.operators.transforms.scalers module
- class nirs4all.operators.transforms.scalers.Derivate(order=1, delta=1, copy=True, axis=1)[source]
Bases:
TransformerMixin,BaseEstimatorFinite-difference spectral derivative along wavelengths (axis=1).
Set axis=0 explicitly for a derivative along samples. That mode depends on sample order and batch composition and requires at least two samples. delta is the spacing on the selected axis; input arrays are not mutated.
- set_transform_request(*, copy: bool | None | str = '$UNCHANGED$') Derivate
Configure whether metadata should be requested to be passed to the
transformmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- class nirs4all.operators.transforms.scalers.LocalStandardNormalVariate(window=11, pad_mode='reflect', constant_values=0.0, copy=True)[source]
Bases:
TransformerMixin,BaseEstimatorLocal Standard Normal Variate (LSNV).
Per-sample local normalization with a sliding window along features. For each sample and feature j:
mean_w = mean(X[…, j-w//2 : j+w//2+1]) std_w = std (X[…, j-w//2 : j+w//2+1]) X’[j] = (X[j] - mean_w) / std_w
- Parameters:
Notes
Operates row-wise (axis=1). Input must be (n_samples, n_features).
std_w==0 → divide by 1 to avoid NaN.
- fit_transform(X, y=None)[source]
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Input samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).
**fit_params (dict) – Additional fit parameters. Pass only if the estimator accepts additional params in its fit method.
- Returns:
X_new – Transformed array.
- Return type:
ndarray array of shape (n_samples, n_features_new)
- class nirs4all.operators.transforms.scalers.Normalize(feature_range=(-1, 1), *, copy=True)[source]
Bases:
TransformerMixin,BaseEstimatorNormalize spectrum using either custom range of linalg normalization
- Parameters:
feature_range (tuple (min, max), default=(-1, 1)) – Desired range of transformed data. If the range is (-1, 1), column L2 normalization is applied, otherwise user defined normalization is applied
copy (bool, default=True) – Set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array).
- fit(X, y=None)[source]
Fit the Normalize transformer on the training data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – The training data.
y (None) – Ignored variable.
- Returns:
self – Returns the instance itself.
- Return type:
- inverse_transform(X)[source]
Transform the normalized data back to the original representation.
- Parameters:
X (array-like of shape (n_samples, n_features)) – The normalized data to be transformed back.
- Returns:
X – The inverse transformed data.
- Return type:
ndarray of shape (n_samples, n_features)
- partial_fit(X, y=None)[source]
Perform incremental fit on the training data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – The training data.
y (None) – Ignored variable.
- Returns:
self – Returns the instance itself.
- Return type:
- transform(X)[source]
Transform the input data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – The input data to be transformed.
- Returns:
X – The transformed data.
- Return type:
ndarray of shape (n_samples, n_features)
- property user_defined
- class nirs4all.operators.transforms.scalers.SimpleScale(copy=True)[source]
Bases:
TransformerMixin,BaseEstimator
- nirs4all.operators.transforms.scalers.derivate(spectra, order=1, delta=1, axis=1)[source]
Computes Nth order derivatives with the desired spacing using numpy.gradient.
- Parameters:
spectra (numpy.ndarray) – NIRS data matrix.
order (int, optional) – Order of the derivation, by default 1.
delta (int, optional) – Spacing along the selected axis, by default 1.
axis (int, default=1) – Wavelength axis (1), or explicit sample-axis derivative (0).
- Returns:
spectra – Derived NIR spectra.
- Return type:
- nirs4all.operators.transforms.scalers.norml(spectra, feature_range=(-1, 1))[source]
Perform spectral normalization with user-defined limits.
- Parameters:
spectra (numpy.ndarray) – NIRS data matrix.
feature_range (tuple (min, max), default=(-1, 1)) – (-1, 1) selects column L2 normalization. Other bounds rescale the matrix-wide minimum and maximum to the requested range.
- Returns:
spectra – Normalized NIR spectra.
- Return type:
- nirs4all.operators.transforms.scalers.spl_norml(spectra)[source]
Perform simple spectral normalization.
- Parameters:
spectra (numpy.ndarray) – NIRS data matrix.
- Returns:
spectra – Normalized NIR spectra.
- Return type: