#!/usr/bin/env python3 """Pick the winning configuration out of the model-selection run. Ranking rule, fixed in advance so the choice cannot be tuned after the fact: the mean CSI over the weeks the targets apply to (W4, W5, W6) in the `daily_capable` framing, which is the strictest framing in which the stated targets are not mathematically out of reach. Ties break on the weekly-event CSI, then on AUC. The raw EC benchmark is ranked alongside but never selected. """ from __future__ import annotations import json import os import sys import numpy as np sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import ehd_common as C TARGET_WEEKS = ["W4", "W5", "W6"] def mean_metric(entry, frame, metric, weeks=TARGET_WEEKS): vals = [entry.get(frame, {}).get(w, {}).get(metric, np.nan) for w in weeks] vals = [v for v in vals if v is not None and np.isfinite(v)] return float(np.mean(vals)) if vals else -np.inf def rank(results): scored = [] for tag, entry in results.items(): scored.append(( mean_metric(entry, "daily_capable", "CSI"), mean_metric(entry, "weekly_all", "CSI"), mean_metric(entry, "daily_capable", "AUC"), tag)) scored.sort(reverse=True) return scored def main(): path = (sys.argv[1] if len(sys.argv) > 1 else os.path.join(C.OUT, "AI_Results", "model_selection.json")) with open(path) as fh: results = json.load(fh) scored = rank(results) sys.stderr.write("%-22s %9s %9s %9s\n" % ("config", "CSI_cap", "CSI_week", "AUC_cap")) for csi, wcsi, auc, tag in scored: sys.stderr.write("%-22s %9.3f %9.3f %9.3f\n" % (tag, csi, wcsi, auc)) for csi, wcsi, auc, tag in scored: if tag.startswith("ec_raw"): continue model, fset = tag.split("/") print("%s %s" % (model, fset)) return print("lgbm_clf F3") if __name__ == "__main__": main()