RangeCut#

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

Bases: XAxisMixin, SelectorMixin, BaseEstimator

Select a contiguous spectral region by index or by x-axis value.

The range can be specified in two ways:

  • By integer indices (start and end)

  • By x-axis values (start and end interpreted against the provided

    x_axis array)

If x_axis is supplied, the closest indices to the given start / end x-axis values are located. Otherwise numeric start / end are treated directly as indices. X-axis values must be in ascending order.

Parameters:
  • start (int, default=0) – Index or x-axis value of the start of the range.

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

  • x_axis (array-like, optional) – X-axis values corresponding to columns. Must be ascending if provided.

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

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

  • end_index (int) – Resolved end index.

  • x_axis (array-like or None) – Selected x-axis values (if provided), else None.

  • wavenumbers (array-like or None) – Deprecated alias for x_axis_.

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, x_axis=wavenumbers)
>>> rc.fit(X)
RangeCut(start=1000, end=2000, x_axis=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