RangeCut#

class chemotools.feature_selection.RangeCut(start: int = 0, end: int = -1, wavenumbers: ndarray | None = None)[source]

Bases: SelectorMixin, BaseEstimator

Select a contiguous spectral region by index or by wavenumber.

The range can be specified in two ways:

  • By integer indices (start and end)

  • By wavenumber values (start and end interpreted against the

    provided wavenumbers array)

If wavenumbers is supplied, the closest indices to the given start / end wavenumber values are located. Otherwise numeric start / end are treated directly as indices. Wavenumbers must be in ascending order.

Parameters:
  • start (int, default=0) – Index or wavenumber of the start of the range.

  • end (int, default=-1) – Index or wavenumber of the end of the range.

  • wavenumbers (array-like, optional) – Wavenumbers corresponding to columns. Must be ascending if provided.

Variables:
  • start_index (int) – Resolved start index.

  • end_index (int) – Resolved end index.

  • wavenumbers (array-like or None) – Selected wavenumbers (if provided), else None.

Examples

>>> from chemotools.feature_selection import RangeCut
>>> from chemotools.datasets import load_fermentation_train
>>> X, _ = load_fermentation_train()
>>> wavenumbers = X.columns.values
>>> rc = RangeCut(start=1000, end=2000, wavenumbers=wavenumbers)
>>> rc.fit(X)
RangeCut(start=1000, end=2000, wavenumbers=wavenumbers)
>>> X_cut = rc.transform(X)
>>> X_cut.shape
(21, 616)
fit(X: ndarray, y=None) RangeCut[source]

Fit the transformer to the input data.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – The input data to fit the transformer to.

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

Returns:

self – The fitted transformer.

Return type:

RangeCut