Preprocessing standardscaler inversetransform - 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.

HomePreprocessingFeature scaling

StandardScaler.InverseTransform

Undoes Transform, returning values on the original scale.

public double[] InverseTransform(ReadOnlySpan<double> samples)
public CsrMatrix InverseTransform(CsrMatrix samples)

The second overload takes a CsrMatrix and returns a new one storing the same positions, each value multiplied by its column's Scale, or copied unchanged when the scaler does not scale: a zero stays a zero, so nothing absent becomes stored.

Parameterssamples is the standardised matrix, row-major, with FeatureCount values per row.

Returns — a new array of the same length, back on the input scale.

ExceptionsArgumentException when samples holds no row, a partial one, or a non-finite value.

The sparse overload throws ArgumentNullException when samples is null, ArgumentException when it holds no row, stores a non-finite value, or its column count is not FeatureCount, and InvalidOperationException when the scaler centres — fit it with WithMean = false, since subtracting a centre would make every absent zero a stored value.

Example — there and back.

using Lodestar.Preprocessing;

double[] samples = [1.0, 10.0, 2.0, 10.0, 4.0, 10.0];
StandardScaler scaler = StandardScaler.Fit(samples, featureCount: 2);

double[] restored = scaler.InverseTransform(scaler.Transform(samples));

double first = restored[0];   // => 1
double second = restored[1];  // => 10

Remarks — exact only up to floating-point rounding: the round trip multiplies by a scale it previously divided by, and neither operation is exact in binary.

A feature whose Scale was forced to 1 does not come back to its own spread. That step threw the spread away rather than recording it, which is the point of forcing it — see StandardScaler.Fit. Such a feature still round-trips to its original values, because its values were all but identical to begin with; what is lost is the ability to recover a spread that was never distinguishable from zero.

Applies to — net10.0, netstandard2.0.

See alsoStandardScaler.Transform, StandardScaler.

⚠️ **GitHub.com Fallback** ⚠️