IndexSelector#
- class chemotools.feature_selection.IndexSelector(features: ndarray | None = None, wavenumbers: ndarray | None = None)[source]
Bases:
SelectorMixin,BaseEstimatorA 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.
- Parameters:
features (narray-like, optional, default=None) – The index of the features to select. Default is None.
wavenumbers (array-like, optional, default=None) – The wavenumbers of the input data. If not provided, the indices will be used instead. Default is None. If provided, the wavenumbers must be provided in ascending order.
- Variables:
features_index (int) – The index of the features to select.
Examples
>>> 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)