XAxisInterpolator#

class chemotools.adaptation.XAxisInterpolator(common_x_axis: ndarray, method: str = 'cubic', left=nan, right=nan)[ソース]

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

Interpolate every row of X onto a shared common_x_axis.

The transformer resamples each row of X from a sample-specific (or shared) input grid x_axis onto a fixed common_x_axis provided at instantiation time.

x_axis is consumed as metadata so it flows correctly through Pipeline, ColumnTransformer, GridSearchCV, cross_validate etc., once metadata routing is enabled via:

sklearn.set_config(enable_metadata_routing=True).

パラメータ:
  • common_x_axis (array-like of shape (n_output_features,)) -- Strictly increasing target grid. transform returns an array with n_output_features columns.

  • method (str, default="cubic") -- The interpolation mode. One of: "linear", "cubic" or "pchip".

  • left (float, default=np.nan) -- Value returned for query points below the input grid (passed to numpy.interp()).

  • right (float, default=np.nan) -- Value returned for query points above the input grid.

変数:
  • common_x_axis (ndarray of shape (n_output_features,)) -- Validated copy of common_x_axis.

  • n_features_in (int) -- Number of input features seen during fit.

  • feature_names_in (ndarray of shape (n_features_in_,)) -- Names of features seen during fit (only if X had names).

fit(X: ndarray, y=None, x_axis=None) XAxisInterpolator[ソース]

Validate input and the configured common_x_axis.

パラメータ:
  • X (array-like of shape (n_samples, n_features)) -- The input data to fit the transformer to.

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

  • x_axis (Ignored) -- Accepted only so that metadata routing through fit_transform (used by Pipeline) generates a set_fit_request method. fit itself does not use it.

戻り値:

self

戻り値の型:

object

transform(X: ndarray, x_axis=None)[ソース]

Interpolate X from x_axis onto common_x_axis_.

x_axis is metadata and must be requested explicitly via set_transform_request(x_axis=True) for routing to work in a Pipeline / GridSearchCV.

パラメータ:
  • X (array-like of shape (n_samples, n_features)) -- Signal values sampled on x_axis.

  • x_axis (array-like, required metadata) -- Either shape (n_features,) (shared grid for every row) or (n_samples, n_features) (per-row grid). Must be strictly increasing along the feature axis.

戻り値:

X_transformed

戻り値の型:

ndarray of shape (n_samples, n_output_features)

fit_transform(X, y=None, **fit_params)[ソース]

Fit to data, then transform it.

fit does not consume x_axis; only transform does. This custom implementation ensures x_axis is forwarded only to transform, not to fit.

パラメータ:
  • X (array-like of shape (n_samples, n_features))

  • y (Ignored)

  • x_axis (array-like, optional metadata) -- Input grid for interpolation, forwarded to transform.

戻り値:

X_new

戻り値の型:

ndarray of shape (n_samples, n_output_features)

get_feature_names_out(input_features=None)[ソース]

Names are the positions of the common grid.

set_fit_request(*, x_axis: bool | None | str = '$UNCHANGED$') XAxisInterpolator

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_axis (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) -- Metadata routing for x_axis parameter in fit.

戻り値:

self -- The updated object.

戻り値の型:

object

set_transform_request(*, x_axis: bool | None | str = '$UNCHANGED$') XAxisInterpolator

Configure whether metadata should be requested to be passed to the transform 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 transform 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 transform.

  • 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_axis (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) -- Metadata routing for x_axis parameter in transform.

戻り値:

self -- The updated object.

戻り値の型:

object