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.

Trial

One point of a sweep: given a parameter value, build the model, fit it under a Stopwatch, predict on the training and test sets, and return the result.

An interface rather than a function reference, as ScoreModel and ScoreMetric are: it crosses the library boundary reliably and reads clearly in a write-up.

Example

class ForestTrial implements Trial {
  @split : DataSplit;
  New(split : DataSplit) { @split := split; }
  method : public : Run(value : Float, name : String, seed : Int) ~ TrialResult {
    forest := RandomForestClassifier->New(value->As(Int), 8, 2, seed);
    sw := Stopwatch->New();
    sw->Start();
    forest->Fit(@split->GetTrainX(), @split->GetTrainY());
    ms := sw->Stop();
    return TrialResult->New(forest->PredictClass(@split->GetTrainX()), @split->GetTrainY(),
      forest->PredictClass(@split->GetTestX()), @split->GetTestY(), ms);
  }
}

Operations

Run # virtual

Runs one trial.

method : public : virtual : Run(value:Float, name:String, seed:Int) ~ TrialResult

Parameters

NameTypeDescription
valueFloatthe swept parameter's value
nameStringthe value's display name (the meaning of a categorical value)
seedIntthe repetition's seed

Return

TypeDescription
TrialResultwhat the trial produced; Nil is refused by the runner