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[,]) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| X | Float | matrix to learn from, normally the training split only |
Return
| Type | Description |
|---|---|
| Bool | true 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
| Name | Type | Description |
|---|---|---|
| X | Float | matrix to fit and transform |
Return
| Type | Description |
|---|---|
| Float | standardized matrix, or Nil if the input could not be fitted |
GetMeans #
The learned per-column means.
method : public : GetMeans() ~ Float[]Return
| Type | Description |
|---|---|
| Float | means, or Nil when unfitted |
GetStandardDeviations #
The learned per-column standard deviations.
method : public : GetStandardDeviations() ~ Float[]Return
| Type | Description |
|---|---|
| Float | deviations, or Nil when unfitted |
IsFitted #
Whether Fit has been called successfully.
method : public : IsFitted() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true when this scaler holds statistics |
MinMaxScaler # native
Scales features to a [0, 1] range (Min-Max normalization)
function : native : MinMaxScaler(data:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| data | Float | input matrix |
Return
| Type | Description |
|---|---|
| Float | scaled 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
| Name | Type | Description |
|---|---|---|
| data | Float | input matrix |
Return
| Type | Description |
|---|---|
| Float | normalized 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
| Name | Type | Description |
|---|---|---|
| data | Float | input matrix |
Return
| Type | Description |
|---|---|
| Float | standardized matrix with mean=0 and std=1 |
Transform #
Applies the learned statistics to a matrix.
method : public : Transform(X:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| X | Float | matrix to transform, with the same column count Fit saw |
Return
| Type | Description |
|---|---|
| Float | standardized 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();
};