Karar-git's picture
Add FINAL-2 pipeline, overnight search scripts and results (11 Nov 2026)
2c2dd6c verified
Raw History Blame Contribute Delete
1.63 kB
"""Sanity test for lgbm_feda: train with the SHOT LABELS SHUFFLED. If the score stays
high, the gain does not come from the shots' labels and something is wrong."""
import os, sys
os.environ.setdefault("NNLAB_THREADS", "4")
sys.path.insert(0, "tools/nnlab")
import numpy as np, pandas as pd
import lab, lgbm_var as V
W = lab.W
d = lab.load(official60=False)
feats = W.feature_names()
mad = pd.read_parquet(W.DATA / "madrid_features.parquet", columns=feats)
ams = pd.read_parquet(W.DATA / "amsterdam_features.parquet", columns=feats)
Xm, Xa = mad[feats].to_numpy(float), ams[feats].to_numpy(float)
Xm, Xa = W.robustz(Xm, W.robustz_fit(Xm)), W.robustz(Xa, W.robustz_fit(Xa))
ctx = {"top": V.top_gain_idx()}
params = {**W.LGBM_PARAMS, **W.RETRAIN_OVERRIDES, "n_jobs": lab.THREADS}
ya = d["_ya"] # scoring only
for n in (5, 200):
shot = lab.shots_for(d, n, 0)
ys = lab.shot_labels(d, shot)
keep = np.setdiff1d(np.arange(len(ya)), shot)
ref = np.load(lab.pred_path("lgbm_feda", n, 0)).astype(float)
f_ref = W.macro_f1(ya[keep], W.decide(ref[keep], d["prior"]))
rng = np.random.default_rng(123 + n)
P = V.fit_predict("lgbm_feda", Xm, d["ym"], Xa, shot, rng.permutation(ys), ctx, params)
f_shuf = W.macro_f1(ya[keep], W.decide(P[keep], d["prior"]))
Pt = V.fit_predict("lgbm_feda", Xm, d["ym"], Xa, shot, ys, ctx, params)
print(f"n={n}: stored true-label F1 {f_ref:.4f} | refit true-label F1 {W.macro_f1(ya[keep], W.decide(Pt[keep], d['prior'])):.4f} "
f"(max abs diff vs stored {np.abs(Pt-ref).max():.2e}) | SHUFFLED-label F1 {f_shuf:.4f}", flush=True)