All examples
Machine learning

Predict on independent unlabeled observations

Align external feature order and units explicitly, reuse fitted preprocessing and retain external prediction identity.

contextual_inference.aner
// Development runtime: explicit independent unlabeled inference.
// Synthetic rule y = 2*x + 3; x is measured in m, target y in J.
import aner.data
import aner.ml
import aner.tensor
import aner.units

var schema = data.schema().column("row_id", "Int64", false)
schema = schema.column("group", "String", false)
schema = schema.unit_column("x", "m", false)
schema = schema.unit_column("y", "J", false)
let observed = data.scan_csv("examples/fixtures/contextual/inference_training.csv", schema, "NA")
    .collect(0, 1048576, 2)
let populations = data.frame(observed, "row_id", "group", "y")
    .partition_groups(List("A", "B"), List(), List("C", "D"))
let scaler = ml.fit_standardizer(populations.train())
let training = scaler.transform(populations.train()).batch(1048576)
let model = ml.fit_linear(training)
let held_out = model.predict(scaler.transform(populations.test()).batch(1048576))

// These new observations have independent IDs and no target column.
// Physical columns carry their explicit source units; metadata stays outside
// the mapped model inputs. Mapping lists source names in fitted feature order.
var external_schema = data.schema().column("note", "String", false)
external_schema = external_schema.unit_column("distance_cm", "cm", false)
external_schema = external_schema.column("observation_id", "Int64", false)
let external_table = data.scan_csv("examples/fixtures/contextual/inference_observations.csv", external_schema, "NA")
    .collect(0, 1048576, 2)
let observations = data.frame(external_table, "observation_id", "", "")
let aligned = scaler.align_inputs(observations, List("distance_cm"))
let inputs = scaler.transform(aligned).batch(1048576)
let prediction = model.predict(inputs)

print(prediction.row_id(0))
print(prediction.row_id(1))
print(prediction.unit())
print(prediction.values().value(0, 0) > 6.999999999 &&
    prediction.values().value(0, 0) < 7.000000001)
print(prediction.values().value(1, 0) > 10.999999999 &&
    prediction.values().value(1, 0) < 11.000000001)
print((prediction.values().value(0, 0) - held_out.values().value(0, 0)) < 0.000000001 &&
    (prediction.values().value(0, 0) - held_out.values().value(0, 0)) > -0.000000001)
print(aligned.role())
print(prediction.explain().contains("fit_authorized=false"))
// inputs.targets(), ml.fit_linear(inputs) and fitting on aligned are errors.
// A raw-input model can be the alignment reference directly. A preprocessed
// model requires alignment against the first ledger and its exact fitted chain.

Make it your experiment.

Use Aner 0.0.5 or newer. Save this program as examples/contextual_inference.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.

Terminal
aner check examples/contextual_inference.aner
aner run examples/contextual_inference.aner

The aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.

Requires the native Aner 0.0.5 or newer with explicit external contextual alignment. Earlier runtimes predate this inference contract. Save the supplied fixtures at their exact source paths. Save each supplied fixture beneath the exact examples/fixtures path shown in the source and run from the project root.

Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.

Dataset sources & attribution
Install Aner