Datasets:
Download code/make_blend_submission.py from DragonDare/protostar-placeholders-final: direct link, hf CLI and curl.
- Browser
- Download file 2.93 kB
-
https://huggingface.co/datasets/DragonDare/protostar-placeholders-final/resolve/main/code/make_blend_submission.py
- Command line
-
hf download hf://datasets/DragonDare/protostar-placeholders-final/code/make_blend_submission.py
-
curl -L -o make_blend_submission.py https://huggingface.co/datasets/DragonDare/protostar-placeholders-final/resolve/main/code/make_blend_submission.py
2.93 kB
| """Final submission: a 50/50 blend of Placeholder_v9-S and combined model v3, forecast as of 2018-12-31. | |
| Chosen by a rule fixed before running code/blend_test.py: on forecast origins 1986, 1994, 2002 and 2010 (train on | |
| years <= origin, forecast the next 7 years, leaderboard formula), the blend's mean Score (4.72) beat both | |
| Placeholder_v9-S (4.51) and combined model v3 (4.50); see reports/blend_test.csv. No 2019+ data and no | |
| leaderboard score was used. | |
| python code/make_blend_submission.py # writes submission.csv (and reports/submission_parts.csv) | |
| python code/check_submission.py | |
| Inputs are those of the two models: data/annual_indices_train_to_2018.parquet, data/daily_warm_days.csv and | |
| data/city_info.csv for v9-S (code/make_submission.py), data/annual_valid.csv and data/city_info.csv for v3 | |
| (code/combo_v3.py). Deterministic. | |
| """ | |
| import sys | |
| import tempfile | |
| from pathlib import Path | |
| import numpy as np | |
| import pandas as pd | |
| HERE = Path(__file__).resolve().parent | |
| sys.path.insert(0, str(HERE)) | |
| ROOT = HERE.parent | |
| from common import CUTOFF_YEAR, FORECAST_YEARS, METRICS, load_valid_annual, wide # noqa: E402 | |
| KEY = ["city_id", "year", "metric"] | |
| WEIGHT_V9S = 0.5 | |
| def v3_forecasts() -> pd.DataFrame: | |
| import combo_v3 as cm | |
| valid = load_valid_annual() | |
| parts = [] | |
| for metric in METRICS: | |
| pred = cm.forecast(wide(valid, metric), metric, cm.METHOD[metric], CUTOFF_YEAR, FORECAST_YEARS) | |
| long = pred.stack().rename("predicted_value").reset_index() | |
| long.columns = ["city_id", "year", "predicted_value"] | |
| long["metric"] = metric | |
| parts.append(long) | |
| return pd.concat(parts)[KEY + ["predicted_value"]] | |
| def main() -> None: | |
| import make_submission as ms | |
| with tempfile.TemporaryDirectory() as tmp: | |
| out = Path(tmp) / "v9s.csv" | |
| ms.main(["--output", str(out)]) | |
| v9s = pd.read_csv(out, dtype={"city_id": str, "metric": str}) | |
| v3 = v3_forecasts() | |
| m = v9s.merge(v3, on=KEY, how="left", suffixes=("_v9s", "_v3"), validate="one_to_one") | |
| if m["predicted_value_v3"].isna().any(): | |
| raise SystemExit("v3 has no forecast for some rows") | |
| m["predicted_value"] = (WEIGHT_V9S * m["predicted_value_v9s"] | |
| + (1 - WEIGHT_V9S) * m["predicted_value_v3"]).round(3) | |
| if len(m) != len(v9s) or not np.isfinite(m["predicted_value"]).all(): | |
| raise SystemExit("incomplete or non-finite blended forecasts") | |
| (ROOT / "reports").mkdir(exist_ok=True) | |
| m.to_csv(ROOT / "reports" / "submission_parts.csv", index=False, lineterminator="\n") | |
| m[KEY + ["predicted_value"]].to_csv(ROOT / "submission.csv", index=False, lineterminator="\n") | |
| print(f"Wrote {len(m):,} blended forecasts (50% Placeholder_v9-S + 50% combined model v3) to submission.csv") | |
| print(m.groupby("metric")[["predicted_value_v9s", "predicted_value_v3", "predicted_value"]].mean().round(2)) | |
| if __name__ == "__main__": | |
| main() | |