IndexSelector#

class chemotools.feature_selection.IndexSelector(features: ndarray | None = None, x_axis: ndarray | None = None, wavenumbers='deprecated')[ソース]

ベースクラス: XAxisMixin, SelectorMixin, BaseEstimator

A transformer that Selects the spectral data to a specified array of features. This array can be continuous or discontinuous. The array of features is specified by:

  • by the indices of the wavenumbers to select,

  • by the wavenumbers to select, the wavenumbers must be provided to the transformer

    when it is initialised. If the wavenumbers are not provided, the indices will be used instead. The wavenumbers must be provided in ascending order.

パラメータ:
  • features (narray-like, optional, default=None) -- The index of the features to select. Default is None.

  • x_axis (array-like, optional, default=None) -- The x-axis values of the input data. If not provided, the indices will be used instead. Default is None. If provided, the values must be in ascending order.

  • wavenumbers (array-like, optional) -- Deprecated alias for x_axis.

変数:

features_index (int) -- The index of the features to select.

サンプル

>>> import numpy as np
>>> from chemotools.feature_selection import IndexSelector
>>> from chemotools.datasets import load_fermentation_train
>>> # Load sample data
>>> X, _ = load_fermentation_train()
>>> # Get wavenumbers as numpy array
>>> wavenumbers = X.columns.values
array([ 428.,  429.,  431., ..., 1830., 1831., 1833.], shape=(1047,))
>>> # Define features to select
>>> range_1 = np.arange(428, 551, 1)
>>> range_2 = np.arange(875, 1001, 1)
>>> features = np.concatenate((range_1, range_2))
>>> # Instantiate the transformer
>>> selector = IndexSelector(features=features, wavenumbers=wavenumbers)
IndexSelector()
>>> selector.fit(X)
>>> # Transform the data
>>> X_selected = selector.transform(X)
>>> X_selected.shape
(21, 183)
fit(X: ndarray, y=None) IndexSelector[ソース]

Fit the transformer to the input data.

パラメータ:
  • X (array-like 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.

戻り値の型:

IndexSelector