bartz.prepcovars.Binner

class bartz.prepcovars.Binner(X, *, key=None)[source]

Abstract base class for predictor binners.

A binner inspects the training predictors at construction time, chooses cutpoints for each predictor, and encapsulates the logic that maps any predictor matrix (training or test) to bin indices via bin.

A predictor value x is mapped to bin i iff c[i - 1] < x <= c[i], where c are the cutpoints chosen for that predictor at construction. A predictor with k cutpoints therefore has k + 1 bins indexed from 0 to k. The number of cutpoints actually used per predictor is exposed as max_split and may differ across predictors; the remaining capacity, if any, is padded internally with the maximum value representable in the dtype of the cutpoints, so binning still produces a valid in-range index.

The constructor takes the training predictors and an optional random key. Concrete subclasses may add their own keyword arguments. Binners that do not use the key still accept it for protocol uniformity and silently ignore it. Binners that need it raise ValueError if it is not provided.

max_split: AbstractVar[UInt[Array, 'p']]

The number of cutpoints actually used for each of the p predictors.

abstractmethod bin(X)[source]

Map predictors to bin indices using the cutpoints chosen at construction.

Parameters:

X (Real[Array, 'p n']) – A matrix with p predictors and n observations. Must have the same number of predictors as the training matrix passed to the constructor.

Returns:

UInt[Array, 'p n'] – Quantized X with minimal data type.