StandardScaler
classin packageklyn.math.preprocessing
public class StandardScaler<T extends AbstractFloat = Float>
StandardScaler

Learns per-feature training statistics and reuses them on new observations. Inputs are two-dimensional [samples, features] floating tensors. Centering and population-standard-deviation scaling are enabled by default. A constant feature uses scale one, so its training values become zero when centered. Statistics use Double; output storage keeps T, including physical FP16. Instances must not be fitted concurrently with fit/transform calls.

Example

scaler = StandardScaler<Float>()

xTrain = scaler.fitTransform(xTrain, inPlace=true)

xTest = scaler.transform(xTest, inPlace=true)

Properties
Modifier and Type Member Description
public readonly property isFitted
isFitted as Boolean
Whether fit has completed successfully.
public readonly property mean
mean as IList<Double>
Immutable applied offsets, cached until the next successful fit.
public readonly property scale
scale as IList<Double>
Immutable applied divisors; one for constants or disabled scaling.
public readonly property withMean
withMean as Boolean
Whether to subtract training means.
public readonly property withStd
withStd as Boolean
Whether to divide by training standard deviations.
Constructors
Modifier and Type Member Description
public StandardScaler
StandardScaler(withMean as Boolean = true, withStd as Boolean = true)
Configures centering and scaling independently, without fitting data.
Methods
Modifier and Type Member Description
public fit
fit(notnull data as NDArray<T>) as StandardScaler<T>
Fits on training observations only.
public fitTransform
fitTransform(notnull data as NDArray<T>, inPlace as Boolean = false) as NDArray<T>
Fits training statistics, then applies them using transform's copy policy.
public inverseTransform
inverseTransform(notnull data as NDArray<T>, inPlace as Boolean = false) as NDArray<T>
Applies x * trainingScale + trainingMean with the same copy policy.
public transform
transform(notnull data as NDArray<T>, inPlace as Boolean = false) as NDArray<T>
Applies (x - trainingMean) / trainingScale using one fused buffer pass.