Skip to main content

Module quantile

Module quantile 

Source
Expand description

Type-7 np.nanpercentile and quantile fitting — sklearn QuantileTransformer._dense_fit.

np.nanpercentile (linear = type-7) places the virtual index h = (n−1)·q/100 over the sorted non-NaN survivors and linearly interpolates the bracketing order statistics. sklearn builds references_ = linspace(0, 1, n_quantiles_), calls np.nanpercentile(X, references * 100, axis=0), then np.maximum.accumulate along axis=0 to force monotonicity (guards against floating-point reversals at repeated values).

When n_samples > subsample, sklearn resamples the entire matrix (shared row indices for all columns) via one resample(X, replace=False) call. We replicate that by drawing indices once then extracting per-column subsets.

Functions§

fit_quantiles
Fit quantile tables for every column. Returns (references, quantiles) where quantiles[j] is the n_quantiles-length vector for column j.