DirectStandardization#

class chemotools.adaptation.DirectStandardization[源代码]

基类:DocLinkMixin, OneToOneFeatureMixin, TransformerMixin, BaseEstimator

Direct Standardization (DS) 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].

参数:

None -- The transformer has no constructor hyperparameters.

变量:
  • V_ds (np.ndarray of shape (n_features, n_transfer_samples)) -- Right singular vectors of the target transfer data X, used as the column basis of the low-rank transformation. Empty (shape (n_features, 0)) when no X_source was provided.

  • B_ds (np.ndarray of shape (n_transfer_samples, n_features)) -- Projection of the source transfer data onto the singular basis. The full transformation is X @ V_ds_ @ B_ds_, which is algebraically equivalent to X @ T_ but requires only O(n_features × n_transfer_samples) storage instead of O(n_features²).

  • x_source_provided (bool) -- Boolean value to flag if X_source was provided during fitting

抛出:

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

参见

PiecewiseDirectStandardization

Localized version using windowed PLS regression.

引用

示例

Basic usage >>> import numpy as np >>> from chemotools.adaptation import DirectStandardization >>> >>> rng = np.random.default_rng(17) >>> X_source = rng.normal(size=(100, 20)) >>> X_target = X_source * 2 - rng.normal(size=(100, 20)) * 0.02 >>> >>> ds = DirectStandardization().fit(X_target, X_source=X_source) >>> X_transf = ds.transform(X_target)

Attributes

n_features_in_

V_ds_

B_ds_

x_source_provided_

n_features_in_: int
V_ds_: ndarray
B_ds_: ndarray
x_source_provided_: bool
fit(X: ndarray, y=None, *, X_source: ndarray | None = None) DirectStandardization[源代码]

Fit the Direct Standardization model.

参数:
  • 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

返回类型:

DirectStandardization

transform(X) ndarray[源代码]

Transform the data from the target space to the source space using the map self.T_.

参数:

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

返回:

X_transf -- The data transformed

返回类型:

np.ndarray of shape (n_samples, n_features)

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

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.

在 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