PiecewiseDirectStandardization#

class chemotools.adaptation.PiecewiseDirectStandardization(window_length: int = 25, n_components: int = 2, scale: bool = True)[ソース]

ベースクラス: DocLinkMixin, OneToOneFeatureMixin, TransformerMixin, BaseEstimator

Piecewise Direct Standardization (PDS) is a transformer used for domain adaptation (calibration) applications. The transformer uses least squares to find a linear map from the target instrument space to the source instrument space, following the implementation by [1] and [2].

パラメータ:
  • window_length (int) -- Half-width (w) of the local spectral window used in PDS

  • n_components (int) -- Number of components to keep for PLS model

  • scale (bool, default = True) -- Whether to scale X and Y in the PLS model

変数:
  • n_features_in (int) -- Number of features seen during fit (set automatically by sklearn).

  • x_mean (np.ndarray of shape (n_features, 2 * window_length + 1) or None) -- Mean of the local X window for each feature. None if fitted with X_source=None (identity transformation).

  • coef (np.ndarray of shape (n_features, 2 * window_length + 1) or None) -- Regression coefficients for each local PLS model. None if fitted with X_source=None (identity transformation).

  • intercept (np.ndarray of shape (n_features,) or None) -- Intercept term for each local PLS model. None if fitted with X_source=None (identity transformation).

  • x_source_provided (bool) -- Boolean flag indicating if X_source was provided during fitting.

例外:

ValueError -- If X and X_source do not have the same shape.

参考

DirectStandardization

Global linear transformation without local windows.

参照

サンプル

>>> import numpy as np
>>> from chemotools.adaptation import PiecewiseDirectStandardization
>>> rng = np.random.default_rng(42)
>>> X = rng.normal(size=(50, 100))
>>> X_source = X * 1.2 + rng.normal(0, 0.1, size=(50, 100))
>>> pds = PiecewiseDirectStandardization(window_length=5, n_components=2)
>>> pds.fit(X, X_source=X_source)
PiecewiseDirectStandardization(n_components=2, window_length=5)
>>> X_transformed = pds.transform(X)
>>> X_transformed.shape
(50, 100)

Attributes

n_features_in_

x_mean_

coef_

intercept_

x_source_provided_

n_features_in_: int
x_mean_: ndarray | None
coef_: ndarray | None
intercept_: ndarray | None
x_source_provided_: bool
fit(X: ndarray, y=None, *, X_source: ndarray | None = None) PiecewiseDirectStandardization[ソース]

Fit the PiecewiseDirectStandardization to the input data.

パラメータ:
  • X (np.ndarray of shape (n_samples, n_features)) -- Data from the target instrument.

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

  • X_source (np.ndarray of shape (n_samples, n_features), optional) -- Data from the source instrument. If None, the transformer defaults to an identity transformation.

戻り値:

self

戻り値の型:

PiecewiseDirectStandardization

transform(X) ndarray[ソース]

Use the trained model to transform the source data

パラメータ:

X (np.ndarray of shape (n_samples, n_features)) -- Input data to transform

戻り値:

X_transformed -- Data transformed

戻り値の型:

np.ndarray of shape (n_samples, n_features)

set_fit_request(*, X_source: bool | None | str = '$UNCHANGED$') PiecewiseDirectStandardization

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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.

パラメータ:

X_source (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) -- Metadata routing for X_source parameter in fit.

戻り値:

self -- The updated object.

戻り値の型:

object