feat: per-sensor holdout metrics and small-model confusion matrix

- train.py emits per-sensor MAE/WAPE/R2 vs the seasonal-naive baseline
- small.py emits the full confusion matrix and per-sensor classifier metrics
- metrics.json now carries the small-model summary for paper support
- regenerate baked artifacts; tests assert the tables are internally consistent
This commit is contained in:
Noel Sabia committed 2026-11-14 06:35:14 +01:00
1 parent 4ea7212b70
commit 000aaed7a5
8 files changed
+386 -10

No files matched your search

+18
View File
@@ -67,6 +67,24 @@ def test_metrics_and_audit():
assert metrics["metrics"]["wape"] < metrics["metrics"]["baseline_wape"]
assert len(metrics["features"]) == 10
assert len(metrics["limits"]) >= 4
assert len(metrics["per_sensor"]) == 8
assert sum(row["n"] for row in metrics["per_sensor"]) == metrics["metrics"]["n_eval"]
assert {row["sensor"] for row in metrics["per_sensor"]} == set(config.USABLE_SENSORS)
for row in metrics["per_sensor"]:
assert row["mae"] >= 0
assert row["baseline_mae"] >= 0
assert 0 <= row["wape"] < 100
assert row["mae_improvement_pct"] > 0
small = _load("small_metrics.json")
matrix = small["confusion_matrix"]
total = matrix["tn"] + matrix["fp"] + matrix["fn"] + matrix["tp"]
assert total == small["metrics"]["n_test"]
assert sum(row["n"] for row in small["per_sensor"]) == total
recomputed = (matrix["tn"] + matrix["tp"]) / total
assert abs(recomputed - small["metrics"]["accuracy"]) < 0.001
assert metrics["small"]["metrics"] == small["metrics"]
assert set(matrix) == {"labels", "tn", "fp", "fn", "tp"}
audit = _load("data_audit.json")
assert audit["all_checks_ok"] is True