A pure MoonBit machine learning evaluation metrics and experiment comparison framework supporting native, wasm-gc, and js backends.
myc1234567/moon_metric_lab
โโโ core # Base numerical primitives, zero-copy views, constants, and structured errors
โโโ classification # Binary & multi-class metrics, confusion matrix, threshold scanner, ROC/PR curves
โโโ regression # Continuous error metrics (MAE/MSE/RMSE/R2/MAPE) and robust losses (Huber/Pinball/Log-Cosh)
โโโ clustering # Internal (Silhouette, CH, DBI) and external (ARI, NMI, FMI) clustering evaluations
โโโ ranking # Information retrieval ranking metrics (DCG@K, NDCG@K, MRR, MAP)
โโโ report # Evaluation containers and automated candidate vs. baseline comparison engine
โโโ visualization # ASCII bar charts, Markdown tables, SVG curve plots, and JSON/CSV exporters
โโโ workflow # Cross-fold aggregation, model ranking, quality gates, and deployment reports
โโโ cmd/main # Standalone CLI showcase executable demonstrator
โโโ examples # Runnable demo projects (binary_demo, comparison_demo)| Package | Description | Key APIs |
|---|---|---|
| core | Numerical foundation & errors | VectorView, MatrixView, validate_same_length, EPSILON |
| classification | Classification evaluation | accuracy, f1_score, log_loss, mcc, roc_curve, ConfusionMatrix |
| regression | Continuous regression metrics | mae, mse, rmse, r2_score, mape, huber_loss, pinball_loss |
| clustering | Clustering evaluation | silhouette_score, calinski_harabasz_score, adjusted_rand_index |
| ranking | IR & recommendation metrics | ndcg_at_k, reciprocal_rank, mean_reciprocal_rank, average_precision |
| report | Benchmark reporting | ModelResult, compare_models, ComparisonReport |
| visualization | Multi-format rendering | to_ascii_bar_chart, to_markdown_table, to_svg_roc_curve, to_csv_string |
| hypothesis_testing | Multi-fold statistics, significance comparison and effect sizes | aggregate_folds_mean, welch_t_test, paired_mean_difference, standard_error, cohens_d |
| workflow | Reproducible experiment-to-release workflow | summarize, compare, rank, evaluate_gate, deployment_report |
[deps]
"myc1234567/moon_metric_lab" = "0.1.3"import {
"myc1234567/moon_metric_lab/classification"
"myc1234567/moon_metric_lab/hypothesis_testing"
"myc1234567/moon_metric_lab/workflow"
}moon add myc1234567/moon_metric_lab@0.1.3test "README classification demo" {
let y_true = [0, 0, 1, 1]
let y_pred = [0, 1, 1, 1]
let y_prob = [0.1, 0.6, 0.8, 0.9]
let acc = @classification.accuracy(y_true, y_pred)
inspect!(acc, content="0.75")
let f1 = @classification.f1_score(y_true, y_pred, pos_label=1)
inspect!(f1 > 0.79 && f1 < 0.81, content="true")
let roc = @classification.roc_curve(y_true, y_prob, pos_label=1)
inspect!(roc.auc, content="1")
}test "README regression demo" {
let y_true = [3.0, -0.5, 2.0, 7.0]
let y_pred = [2.5, 0.0, 2.0, 8.0]
let rmse_val = @regression.rmse(y_true, y_pred)
inspect!(rmse_val > 0.61 && rmse_val < 0.62, content="true")
let r2 = @regression.r2_score(y_true, y_pred)
inspect!(r2 > 0.94, content="true")
let huber = @regression.huber_loss(y_true, y_pred, delta=1.0)
inspect!(huber, content="0.1875")
}test "README clustering demo" {
let x = [[1.0, 1.0], [1.2, 0.8], [5.0, 5.0], [5.2, 4.8]]
let labels = [0, 0, 1, 1]
let sil = @clustering.silhouette_score(x, labels)
inspect!(sil > 0.8, content="true")
let ari = @clustering.adjusted_rand_index([0, 0, 1, 1], [1, 1, 0, 0])
inspect!(ari, content="1")
}test "README ranking demo" {
let y_rels = [3.0, 2.0, 3.0, 0.0, 1.0]
let y_scores = [0.9, 0.8, 0.7, 0.6, 0.5]
let ndcg = @ranking.ndcg_at_k(y_rels, y_scores, k=3)
inspect!(ndcg > 0.8, content="true")
}test "README comparison demo" {
let baseline = @report.ModelResult::new("LogReg", "classification")
baseline.add_metric("accuracy", 0.80)
baseline.add_metric("log_loss", 0.45)
let candidate = @report.ModelResult::new("XGBoost", "classification")
candidate.add_metric("accuracy", 0.88)
candidate.add_metric("log_loss", 0.32)
let comp = @report.compare_models(baseline, candidate)
let table = comp.to_table_string()
inspect!(table.contains("IMPROVED"), content="true")
}test "README significance demo" {
let before = @core.Vector::from_array([0.70, 0.75, 0.80, 0.85])
let after = @core.Vector::from_array([0.75, 0.80, 0.85, 0.90])
let difference = @hypothesis_testing.paired_mean_difference(before, after)
inspect!(difference > 0.049 && difference < 0.051, content="true")
let effect = @hypothesis_testing.cohens_d(before, after)
inspect!(effect < 0.0, content="true")
}test "README release workflow demo" {
let candidate = @workflow.Experiment::new("calibrated-model", "classification")
candidate.add_metadata("dataset", "UCI Breast Cancer Wisconsin")
for i, auc in [0.94, 0.95, 0.93, 0.94] {
let fold = @workflow.FoldObservation::new(i + 1)
fold.add_metric("roc_auc", auc)
fold.add_metric("log_loss", 1.0 - auc)
candidate.add_fold(fold)
}
let summary = @workflow.summarize(candidate)
let gate = @workflow.evaluate_gate(summary, "production-v1", [
@workflow.GateRule::new("roc_auc").with_minimum(0.92),
@workflow.GateRule::new("log_loss").with_maximum(0.10),
])
inspect!(gate.is_passed(), content="true")
inspect!(@workflow.summary_to_markdown(summary).contains("roc_auc"), content="true")
}# Check compilation across all targets (Wasm-GC, Wasm, JS, Native)
moon check --target all
# Run the complete test suite on every available backend
moon test --target all --deny-warn
# Generate updated package interfaces
moon info
# Verify that generated public interfaces are already up to date
git diff --exit-code -- '**/pkg.generated.mbti'
# Run the full CLI evaluation showcase
moon run --target wasm-gc cmd/mainA pure MoonBit machine learning evaluation metrics and experiment comparison framework supporting native, wasm-gc, and js backends.