Preprocessing robustscaler fit - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Preprocessing is 0.1.0 โ€” read its documentation.

Home โ€บ Preprocessing โ€บ Feature scaling

RobustScaler.Fit

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.5

Remarks โ€” the percentile is numpy.percentile's linear interpolation (Hyndman and Fan's type 7): at h = (n โˆ’ 1)ยทq/100 the value is x[โŒŠhโŒ‹] + (h โˆ’ โŒŠhโŒ‹)ยท(x[โŒŠhโŒ‹+1] โˆ’ x[โŒŠhโŒ‹]) over the sorted column. Neither quantile already in this repository is that convention โ€” SplitConformal.Quantile takes the conformal order statistic โŒˆ(n+1)(1โˆ’ฮฑ)โŒ‰ and Lodestar.Metrics averages a weighted percentile โ€” so it is written here rather than shared, and this page says so instead of leaving a reader to assume.

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.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ