Preprocessing robustscaler fit - CyrilB1531/lodestar GitHub Wiki
Development build. This page describes
main, not a released package. The latest published Lodestar.Preprocessing is 0.2.0 — read its documentation.
Home › Preprocessing › Feature scaling
Fits a scaler on a row-major sample matrix.
public static RobustScaler Fit(ReadOnlySpan<double> samples, int featureCount, RobustScalerOptions options = null)
public static RobustScaler Fit(CsrMatrix samples, RobustScalerOptions options = null)Parameters — samples is the sample matrix, row-major: featureCount values per row.
featureCount is how many values each row carries. options chooses which steps to apply and
between which percentiles; null applies both, at the quartiles.
Returns — a fitted RobustScaler.
Exceptions — ArgumentNullException when the sparse overload is given no matrix.
ArgumentOutOfRangeException when featureCount is not positive, the percentile range is not
0 ≤ lower ≤ upper ≤ 100, or centring is asked of a sparse matrix. ArgumentException when samples holds no row,
a partial one, or a non-finite value.
Example — the percentile interpolates between two values when it falls between them.
using Lodestar.Preprocessing;
// Six values: the lower quartile sits at h = (6 - 1) * 0.25 = 1.25, between 1 and 2.
double[] six = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0];
RobustScaler scaler = RobustScaler.Fit(six, featureCount: 1);
double centre = scaler.Centre![0]; // => 2.5
double scale = scaler.Scale![0]; // => 2.5Remarks — the percentile is numpy.percentile's linear interpolation (Hyndman and Fan's
type 7), at h = (n − 1)·q/100 over the sorted column and through numpy's own _lerp, to the last
bit. The centre is np.nanmedian along the rows: np.ma.median below 600 rows (the two middle
values added and halved, the middle one added to itself where the count is odd) and np.median
from there. Both come from the numpy grid Lodestar.Metrics shares
(#1230); neither is SplitConformal.Quantile's conformal order statistic
⌈(n+1)(1−α)⌉.
Five values put the quartiles on an index (h = 1 and h = 3) and six put them between two,
which is the pair worth reading twice.
The interpercentile range is floored to 1 below 10·eps, the rule
MinMaxScaler.Fit carries.
The sparse overload takes a CsrMatrix and refuses centring, as StandardScaler's does and for
the same reason. The percentiles still read the whole column, the absent zeros included — which is
why a mostly-zero column's quartiles are usually zero and its range is floored to 1.
Applies to — net10.0, netstandard2.0.
See also — RobustScaler, RobustScalerOptions.