// The notebook launches this script with its own standard streams.
// The scientist first inspects and approves the private energy-401.run in a separate Aner process.
import aner.agent
import aner.data
import aner.ml
import aner.tensor

let schema = data.schema()
    .column("row_id", "Int64", false)
    .column("building_id", "String", false)
    .column("temperature", "Float64", false)
    .column("occupancy", "Float64", false)
    .column("energy", "Float64", false)
let table = data.scan_csv("examples/fixtures/contextual/energy.csv", schema, "NA").collect(16, 1048576, 4)
let frame = data.frame(table, "row_id", "building_id", "energy", List("", "", "degC", "1", "kWh"))
let split = frame.partition_groups(List("B0", "B1", "B2", "B3"), List("B4", "B5"), List("B6", "B7"))
let scaler = ml.fit_standardizer(split.train())
let fit = ml.fit_linear(scaler.transform(split.train()).batch(1048576))
let run = agent.open_run("energy-401.run")
// Record scoped prediction responses so the scientist can export them for offline review.
agent.serve_mcp(run, fit, scaler, split.validation(), true)
