Download code/scripts/unified_ladder.py from eduzrh/LNPBench: direct link, hf CLI and curl.
- Browser
- Download file 3.01 kB
-
https://huggingface.co/datasets/eduzrh/LNPBench/resolve/main/code/scripts/unified_ladder.py
- Command line
-
hf download hf://datasets/eduzrh/LNPBench/code/scripts/unified_ladder.py
-
curl -L -o unified_ladder.py https://huggingface.co/datasets/eduzrh/LNPBench/resolve/main/code/scripts/unified_ladder.py
3.01 kB
| """Build the definitive unified-budget k-shot ladder. | |
| Every method receives the same pilot batch (k% of the target study, same | |
| draw, same seeds) and is evaluated on the unlabelled remainder. Sources: | |
| * ``fewshot_ens_refit.csv`` - our refit / refit+ensemble arms, k=5-20% | |
| * ``fewshot_kscale.csv`` - RF arms (refit / ens4 / ens6 / fp), k=30-80% | |
| * ``fewshot_kscale_xgb.csv`` - XGBoost arms, k=30-80% | |
| * ``fewshot_final.csv`` - adapted-tree mixes, k=10/50% | |
| * ``fewshot_baselines*.csv`` - same-budget CatBoost / XGBoost baselines | |
| PYTHONPATH=src python scripts/unified_ladder.py | |
| """ | |
| from __future__ import annotations | |
| from pathlib import Path | |
| import pandas as pd | |
| R = Path(__file__).resolve().parents[1] / "results" | |
| def read(name: str) -> pd.DataFrame | None: | |
| p = R / name | |
| return pd.read_csv(p) if p.exists() else None | |
| def main() -> None: | |
| ours = [] | |
| er = read("fewshot_ens_refit.csv") | |
| if er is not None: | |
| d = er[(er["use"] == "refit+ens") & (er["select"] == "random")] | |
| ours.append(d.assign(arm="refit+ens")) | |
| ks = read("fewshot_kscale.csv") | |
| if ks is not None: | |
| ours.append(ks[ks["arm"].isin(["ens4", "fp"])].assign(arm=ks["arm"])) | |
| kx = read("fewshot_kscale_xgb.csv") | |
| if kx is not None: | |
| ours.append(kx[kx["arm"].isin(["xgb_ens", "xgb_fp"])].assign(arm=kx["arm"])) | |
| ff = read("fewshot_final.csv") | |
| if ff is not None: | |
| ours.append(ff[ff["arm"].isin(["trees3_fp", "trees4"])].assign(arm=ff["arm"])) | |
| ours = pd.concat(ours) | |
| base = [] | |
| for name, model_col in [("fewshot_baselines.csv", "model"), | |
| ("fewshot_baselines_ext.csv", "model"), | |
| ("fewshot_baselines_k3.csv", "model")]: | |
| df = read(name) | |
| if df is not None: | |
| base.append(df) | |
| base = pd.concat(base) | |
| rows = [] | |
| for k in sorted(ours["k_shot"].unique()): | |
| o = ours[ours["k_shot"] == k].groupby("arm")["spearman"].agg(["mean", "size"]) | |
| b = base[base["k_shot"] == k].groupby("model")["spearman"].agg(["mean", "size"]) | |
| if not len(o) or not len(b): | |
| continue | |
| best_base = b["mean"].max() | |
| best_base_name = b["mean"].idxmax() | |
| best_ours = o["mean"].max() | |
| best_ours_name = o["mean"].idxmax() | |
| rows.append({"k_shot": k, | |
| "best_baseline": best_base, "best_baseline_name": best_base_name, | |
| "best_ours": best_ours, "best_ours_name": best_ours_name, | |
| "delta": best_ours - best_base, | |
| "rel_improve": best_ours / best_base - 1, | |
| **{f"ours_{a}": round(v, 4) for a, v in o["mean"].items()}, | |
| **{f"base_{m}": round(v, 4) for m, v in b["mean"].items()}}) | |
| out = pd.DataFrame(rows) | |
| out.to_csv(R / "unified_ladder.csv", index=False) | |
| print(out.round(4).to_string(index=False)) | |
| print(f"\nwrote {R/'unified_ladder.csv'}") | |
| if __name__ == "__main__": | |
| main() | |