v2026.11.2
All Bundles
Bundle

Experiment support for a parameter sweep: a deterministic stratified hold-out split, class-ratio resampling of the training half against a fixed test set, a wall-clock stopwatch and label helpers. Compile with -lib ml,ml_lab,csv,json, or with the ai alias group. Design: docs/ML_LAB_SUPPORT_DESIGN.md.

Labels

Label helpers for labels that arrive as strings or need to become strata.

TableEncoder already maps a CsvTable's label column; these cover a String[] read any other way, and the multi-class codes a split or k-fold can be stratified by.

Example

names := Labels->Column(table, "class");
y := Labels->ToBinaryExcept(names, "normal");         # attacks are positive
families := Labels->ToIndices(names, Labels->Classes(names));
split := Partition->TrainTest(X, y, families, 0.3, 42);

Operations

Classes # function

Distinct values in first-seen order.

function : Classes(values:String[]) ~ String[]

Parameters

NameTypeDescription
valuesStringlabels

Return

TypeDescription
Stringthe distinct values; raises LabError for Nil input

Column # function

One column of a parsed table's DATA rows, as strings; the header row is skipped. A missing cell is Nil.

function : Column(table:CsvTable, name:String) ~ String[]

Parameters

NameTypeDescription
tableCsvTablea parsed CsvTable whose row 0 is the header
nameStringthe column's header

Return

TypeDescription
Stringone value per data row; raises LabError when the table is unparsed or the column is missing

ToBinary # function

True where the value equals the positive label.

function : ToBinary(values:String[], positive:String) ~ Bool[]

Parameters

NameTypeDescription
valuesStringone label per row
positiveStringthe value that is the positive class

Return

TypeDescription
Boolone Bool per row; raises LabError for Nil input

ToBinaryExcept # function

True everywhere except where the value equals the negative label: the intrusion-detection shape, one benign value against many attack names.

function : ToBinaryExcept(values:String[], negative:String) ~ Bool[]

Parameters

NameTypeDescription
valuesStringone label per row
negativeStringthe value that is the negative class

Return

TypeDescription
Boolone Bool per row; raises LabError for Nil input

ToIndices # function

The index of each value in a class list, as strata codes.

function : ToIndices(values:String[], classes:String[]) ~ Float[]

Parameters

NameTypeDescription
valuesStringlabels
classesStringthe classes, e.g. from Classes(values) on the training labels

Return

TypeDescription
Floatone code per value, -1.0 for a value not in classes; raises LabError for Nil input