Pima Diabetes classifier
Load Pima Indians Diabetes by name, make a seeded split, fit standardization on training rows and evaluate a dense binary classifier on held out data.
// Pima Indians Diabetes: Smith et al. (1988), historical OpenML 37 v1 copy.
// See datasets/diabetes/README.md and THIRD_PARTY_DATA.md for source status.
// Educational classification example; no accuracy or clinical-use claim.
import aner.dataset
import aner.nn
import aner.ml
// 1. Load all 768 rows and 8 numeric predictors, with 2 outcome classes.
// Preserve source zeros, including missing-measurement placeholders.
// This example fits standardization only; it does not replace or impute zeros.
let diabetes = dataset.load("diabetes")
print("Diabetes: rows, features, classes")
print(dataset.rows(diabetes))
print(dataset.cols(diabetes))
print(dataset.classes(diabetes))
// 2. Split first: seeded, stratified 80/20 train/test views (614/154 rows).
let split = diabetes.split(test: 0.2, seed: 2026)
print("Training rows, held-out test rows")
print(dataset.rows(split.train()))
print(dataset.rows(split.test()))
// 3. Declare preprocessing and an 8 -> 12 -> 2 classifier with raw logits.
// standardize: true fits column means/scales ONLY when fit receives training rows.
let network = nn.sequential(seed: 42)
.dense(inputs: 8, outputs: 12, initialization: "xavier")
.tanh()
.dense(inputs: 12, outputs: 2, initialization: "xavier")
let pipeline = ml.classifier(network, standardize: true,
loss: "cross_entropy", optimizer: "adam")
.on(device: "cpu", precision: "Float64", policy: "preserve")
// 4. Fit preprocessing and train on training rows only, for a fixed horizon.
// The fitted model owns these training-fitted statistics and model parameters.
let fitted = pipeline.fit(split.train(), epochs: 400, rate: 0.01)
print("Training-fitted pregnancies mean, scale")
print(nn.value(ml.center(fitted), 0, 0))
print(nn.value(ml.scale(fitted), 0, 0))
// 5. Evaluate the held-out test once; reuse the fitted scaler without refitting.
// Test rows do not choose parameters, preprocessing, or the training horizon.
print(fitted.evaluate(split.test()).summary())
Run step by step in VS Code.
The notebook separates loading, splitting, model configuration, training, and evaluation into cells. It opens with empty outputs, shared variables, and Development inspection enabled.
- Install a compatible native Aner executable and VS Code extension using the editor guide. These datasets and fitted classifier pipelines require the current native development engine.
- Download the
.anernbnotebook and open it in your VS Code project. If it appears as JSON, choose Reopen Editor With… → Aner Notebook. - Select the
Aner — notebookkernel and keep Shared variables active. Run code cells from top to bottom, or choose Run All. Later cells reuse the datasets, network, and fitted model from earlier cells. - Read the results below each cell. Open Inspector to inspect native variables. Use Aner: Open Development Training Report to inspect the recorded loss, topology, and available gradients after the fitting cell completes.
After changing an earlier cell, rerun its dependent cells. Use Aner: Restart Notebook Session, then Run All, for a clean experiment. Saved outputs are historical; reopening the file starts without live variables. The notebook guide explains session state, inspection, and runtime controls.
Make it your experiment.
With Aner installed, save this program as examples/neural_diabetes_concise.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/neural_diabetes_concise.aner
aner run examples/neural_diabetes_concise.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Use the current native Aner development engine with dataset.load, the bundled Titanic and Pima Indians Diabetes loaders, and fitted classifier pipelines. Earlier native packages may predate these dataset loaders. No CSV preparation or network download is required. The seeded split happens before the pipeline fits standardization and model parameters on training rows; evaluation uses the held out test partition.
Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution