PeaBox Lab › PeaLang › Learn › Chapter 35 › Lesson 2

Part V — The Modern Experience Layer · Chapter 35 · Lesson 2 of 2

AutoML random search and ONNX export

Finding a good model configuration by hand is indistinguishable from superstition wearing a hoodie. PeaLang 3.1.39 exposes a deliberately simple, seeded search primitive through stats.

Random search for model selection

let space = {
  "n_trees": [50, 100, 200, 400],
  "max_depth": [3, 5, 8, null],
  "min_samples_split": [2, 5, 10]
}
let result = stats.random_search("forest", X, y, "classification", space, 20, 42)

print result.n_candidates   # 20
print result.task           # "classification"
print result.best_model     # { "estimator": "random_forest" }

The PeaLang-facing API is positional: random_search(model_type, X, y, task, param_space, n_iter=10, seed=42, *args). It returns n_candidates, task, best_model (a record with estimator) and best_score. The seed makes the sampled configurations reproducible and n_iter bounds the loop. This is the simple ai_ml.py routine exported to stats; it samples values from param_space and uses a stub score based on the configuration record, so it does not fit or evaluate X/y. Do not confuse it with selection.random_search, which has a different signature.

Where this fits with Chapter 19

ONNX export

let path = stats.export_to_onnx(model, input_sample, "model.onnx", 14)
print path

export_to_onnx(model, input_sample, path="model.onnx", opset_version=14) writes a small JSON metadata file (opset, path, input shape, timestamp) and returns the path. It is a stub, not a runnable ONNX graph: verify any round trip before treating the output as an interchange artifact. Three other exports are easy to mix up: stats.model_to_onnx(model, model_type="auto") and stats.tree_to_onnx(tree_model, feature_names=None) return ONNX-like records, while stats.export_model(model, compact=False) returns a versioned pealang.model document. They are not the same as export_to_onnx.

A realistic AutoML workflow

# 1. Split honestly: train / validation / frozen holdout (Chapter 19).
# 2. Sample configs within each candidate family with stats.random_search.
# 3. Fit and score the sampled configs with Chapter 19 evaluation tools.
# 4. Retrain the chosen family on train+validation with the winning config.
# 5. Report exactly once on the frozen holdout.
# 6. Register through the Chapter 20 lifecycle — bundle, sign, promote.

Failure modes worth knowing

Guided practice

← Previous Next →