Download code/scorer.py from Tonic/protostar-climate-2026: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/datasets/Tonic/protostar-climate-2026/resolve/main/code/scorer.py
- Command line
-
hf download hf://datasets/Tonic/protostar-climate-2026/code/scorer.py
-
curl -L -o scorer.py https://huggingface.co/datasets/Tonic/protostar-climate-2026/resolve/main/code/scorer.py
1.68 kB
| """Official-style scoring: MAE per metric, skill vs the 30-year-average baseline. | |
| Score = 100 * max(0, mean_m (1 - MAE_m / MAE_ref,m)) | |
| Re-implemented from the challenge Space scoring.py (pure, no answer key needed | |
| when truth is supplied from held-out training years). | |
| """ | |
| from __future__ import annotations | |
| import numpy as np | |
| import pandas as pd | |
| from dataset import METRICS | |
| def score_forecasts(truth: pd.DataFrame, pred: pd.DataFrame, | |
| reference: pd.DataFrame) -> dict: | |
| """truth/pred/reference: long frames with city_id, Year, metric, value. | |
| reference = the 30-year-average baseline forecasts on the same rows. | |
| Skill is pooled (all city-years) per metric, as on the leaderboard. | |
| """ | |
| key = ["city_id", "Year", "metric"] | |
| t = truth.rename(columns={"value": "actual"}) | |
| p = pred.rename(columns={"value": "pred"})[key + ["pred"]] | |
| r = reference.rename(columns={"value": "ref"})[key + ["ref"]] | |
| rows = t.merge(p, on=key, how="inner").merge(r, on=key, how="inner") | |
| rows["err"] = (rows["pred"] - rows["actual"]).abs() | |
| rows["err_ref"] = (rows["ref"] - rows["actual"]).abs() | |
| mae, mae_ref, skill = {}, {}, {} | |
| for m in METRICS: | |
| sub = rows[rows["metric"] == m] | |
| if sub.empty: | |
| continue | |
| mae[m] = float(sub["err"].mean()) | |
| mae_ref[m] = float(sub["err_ref"].mean()) | |
| skill[m] = 1.0 - mae[m] / mae_ref[m] if mae_ref[m] > 0 else 0.0 | |
| return { | |
| "score": 100.0 * max(0.0, float(np.mean(list(skill.values())))) if skill else 0.0, | |
| "mae": mae, "mae_ref": mae_ref, "skill": skill, | |
| "n_rows": int(len(rows)), | |
| } | |