Trust the model,
not just run it.
Score it, diagnose it, explain it, calibrate its probabilities, and flag the weird rows — the tools that turn a fitted model into one you can defend.
Metrics, VIF, SHAP, figures.
Any predictor scores itself on a labelled set (core). explain adds SHAP and permutation importance; diagnostics adds OLS VIF / residuals / influence; viz renders self-contained SVGs (a pure-Rust backend, no system fonts).
let mut rf = RandomForest::new().n_trees(60); rf.fit(&train)?; print!("{}", rf.evaluate(&test)?); // accuracy / precision / recall / F1 // explain (feature = "explain") let shap = rf.explain(&Explainer::kernel().nsamples(80), test.features())?; let perm = permutation_importance(&rf, &test, 8, 0)?; // diagnostics (feature = "diagnostics") · viz (feature = "viz") let diag = Diagnostics::of(®)?; println!("R² = {:.4}, VIF = {:?}", diag.r_squared(), diag.vif()); let auc = viz::roc_svg(test.target(), &scores, "roc.svg", (520, 420))?;
cargo run --example insight --features "diagnostics explain viz"
Probabilities that mean what they say.
With calibration, wrap any ProbaPredictor (a LogisticRegression, or a probability-averaged soft vote) in a CalibratedClassifier — itself a ProbaPredictor, so it composes. Fit the calibrator on a held-out set.
let mut clf = LogisticRegression::new(); clf.fit(&train)?; let calibrated = CalibratedClassifier::isotonic(clf).fit(&holdout)?; // or ::platt(..) let probs = calibrated.predict_proba(&test)?; // check calibration directly: predicted vs. observed, per bin let curve = reliability_curve(&probs.column(1), test.target(), 10);
Spot the rows that don't belong.
With anomaly, Mahalanobis (covariance-aware distance) and KnnScore (k-th nearest-neighbour distance) score each row unsupervised — higher is more anomalous. Both implement a shared OutlierDetector trait, so they're interchangeable.
let mut m = Mahalanobis::new(); // or KnnScore::new(k) m.fit(&x)?; let scores = m.score(&x)?; // higher = more anomalous let flags = m.is_outlier(&x, 3.0)?;
cargo run --example trust --features "calibration anomaly"
KnnScore, the covariance Xcᵀ·Xc for Mahalanobis. With gpu-compute, KnnScore::new(k).on_gpu() and Mahalanobis::new().on_gpu() run those on the GPU (via portable gpu::pairwise_sqdist / gpu::gemm primitives over Vulkan/Metal/DX12), matching the CPU path within tolerance and falling back to CPU when no GPU is present. Worth it for large data; CPU stays the default.