pub fn quantile_transform<F: Float + Send + Sync + 'static>(
x: &Array2<F>,
axis: usize,
n_quantiles: usize,
output_distribution: OutputDistribution,
subsample: usize,
) -> Result<Array2<F>, FerroError>Expand description
Transform features using quantiles information — the standalone,
estimator-less API mirroring scikit-learn’s quantile_transform free
function (sklearn/preprocessing/_data.py:2978,:3107-3119).
This is a thin wrapper that reuses the fitted estimator: it constructs a
QuantileTransformer with the given parameters, then runs the SHIPPED
Fit::fit → Transform::transform (i.e. fit_transform) — it does NOT
reimplement any quantile math. Each call fits on the supplied data and
immediately transforms it (sklearn n = QuantileTransformer(...); X = n.fit_transform(X), :3107-3116).
§Parameters
x— the data to transform, shape(n_samples, n_features).axis— axis along which to transform (sklearnaxis=0default,:3013-3015).axis == 0transforms each feature (column) independently —fit_transform(X)(:3115-3116).axis == 1transforms each sample (row) independently —fit_transform(X.T).T(:3117-3118): the matrix is transposed (so rows become columns / the per-feature path operates on each original row), fit-transformed, then transposed back to the original orientation.n_quantiles— number of quantile reference landmarks (sklearn default 1000, clamped ton_samples,:3017-3023).output_distribution—OutputDistribution::Uniform(sklearn default,:3025-3027) orOutputDistribution::Normal.subsample— maximum samples used to estimate the quantiles (0= use all). See the scope note below.
§Scope
Unlike sklearn’s quantile_transform, the ignore_implicit_zeros,
random_state, and copy keyword arguments are not surfaced: this path
is dense, deterministic, and always returns a freshly allocated array
(copy is implicitly True). The subsample parameter is threaded to the
estimator, but the actual random subsampling is REQ-6 (#1324,
NOT-STARTED): for n_samples > subsample the deterministic strided pick is
used instead of sklearn’s RNG draw, so this function matches sklearn’s output
only when n_samples <= subsample (use subsample=None or a large value on
the sklearn side to compare). NaN is disregarded when fitting and preserved
in the output (sklearn Notes, :3078-3079).
§Errors
Returns FerroError::InvalidParameter if axis is neither 0 nor 1
(mirroring sklearn’s ValueError("axis should be either equal to 0 or 1. Got axis={axis}")). Also propagates any error from the underlying
Fit::fit / Transform::transform (e.g.
FerroError::InsufficientSamples for fewer than 2 rows along the chosen
axis, FerroError::InvalidParameter for n_quantiles < 2 or non-finite
±inf input).
§Examples
use ferrolearn_preprocess::quantile_transformer::{quantile_transform, OutputDistribution};
use ndarray::array;
let x = array![[1.0_f64], [2.0], [3.0], [4.0], [5.0]];
let out = quantile_transform(&x, 0, 5, OutputDistribution::Uniform, 0).unwrap();
// First maps to 0.0, last to 1.0.
assert!((out[[0, 0]] - 0.0_f64).abs() < 1e-9);
assert!((out[[4, 0]] - 1.0_f64).abs() < 1e-9);