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
| Name | Type | Description |
|---|---|---|
| values | String | labels |
Return
| Type | Description |
|---|---|
| String | the 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
| Name | Type | Description |
|---|---|---|
| table | CsvTable | a parsed CsvTable whose row 0 is the header |
| name | String | the column's header |
Return
| Type | Description |
|---|---|
| String | one 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
| Name | Type | Description |
|---|---|---|
| values | String | one label per row |
| positive | String | the value that is the positive class |
Return
| Type | Description |
|---|---|
| Bool | one 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
| Name | Type | Description |
|---|---|---|
| values | String | one label per row |
| negative | String | the value that is the negative class |
Return
| Type | Description |
|---|---|
| Bool | one 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
| Name | Type | Description |
|---|---|---|
| values | String | labels |
| classes | String | the classes, e.g. from Classes(values) on the training labels |
Return
| Type | Description |
|---|---|
| Float | one code per value, -1.0 for a value not in classes; raises LabError for Nil input |