v2026.10.0
All Bundles
Bundle

Core machine learning types: the seedable Random generator, Matrix2D linear algebra and activations, matrix reference holders, the NeuralNetwork and CSV-backed MatrixReader. Compile with -lib ml.

FeatureScaler

Feature scaling and normalization utilities

Operations

Fit #

Learns each column's mean and standard deviation from this matrix.

method : public : Fit(X:Float[,]) ~ Bool

Parameters

NameTypeDescription
XFloatmatrix to learn from, normally the training split only

Return

TypeDescription
Booltrue when the statistics were learned, false for empty input

Example

scaler := FeatureScaler->New();
scaler->Fit(train);
train_z := scaler->Transform(train);
test_z := scaler->Transform(test);

FitTransform #

Fits on this matrix and transforms it in one call. For the training split only.

method : public : FitTransform(X:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
XFloatmatrix to fit and transform

Return

TypeDescription
Floatstandardized matrix, or Nil if the input could not be fitted

GetMeans #

The learned per-column means.

method : public : GetMeans() ~ Float[]

Return

TypeDescription
Floatmeans, or Nil when unfitted

GetStandardDeviations #

The learned per-column standard deviations.

method : public : GetStandardDeviations() ~ Float[]

Return

TypeDescription
Floatdeviations, or Nil when unfitted

IsFitted #

Whether Fit has been called successfully.

method : public : IsFitted() ~ Bool

Return

TypeDescription
Booltrue when this scaler holds statistics

MinMaxScaler # native

Scales features to a [0, 1] range (Min-Max normalization)

function : native : MinMaxScaler(data:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
dataFloatinput matrix

Return

TypeDescription
Floatscaled matrix with values in [0, 1]

New # constructor

Constructor for a scaler that learns its statistics once and reapplies them. The static functions below standardize whatever matrix they are handed, which makes them unusable for train/test work: scaling test data by its own mean and deviation leaks test statistics into the evaluation, and the two halves end up on different scales besides. Fit on the training split, Transform both.

New()

Normalize # native

Normalizes each row to unit norm (L2 normalization)

function : native : Normalize(data:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
dataFloatinput matrix

Return

TypeDescription
Floatnormalized matrix where each row has L2 norm = 1

StandardScaler # native

Standardizes features by removing mean and scaling to unit variance (Z-score normalization)

function : native : StandardScaler(data:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
dataFloatinput matrix

Return

TypeDescription
Floatstandardized matrix with mean=0 and std=1

Transform #

Applies the learned statistics to a matrix.

method : public : Transform(X:Float[,]) ~ Float[,]

Parameters

NameTypeDescription
XFloatmatrix to transform, with the same column count Fit saw

Return

TypeDescription
Floatstandardized matrix, or Nil if this scaler is unfitted or the column count differs

Example

test_z := scaler->Transform(test);
if(test_z = Nil) {
  "unfitted, or wrong column count"->PrintLine();
};