Download code/ampd/evaluation/postprocess.py from fryabcfry/cs4486-amp-pd-checkpoints: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/fryabcfry/cs4486-amp-pd-checkpoints/resolve/main/code/ampd/evaluation/postprocess.py
- Command line
-
hf download hf://fryabcfry/cs4486-amp-pd-checkpoints/code/ampd/evaluation/postprocess.py
-
curl -L -o postprocess.py https://huggingface.co/fryabcfry/cs4486-amp-pd-checkpoints/resolve/main/code/ampd/evaluation/postprocess.py
1.24 kB
| """Optional post-processing rules (reported as ablations).""" | |
| from __future__ import annotations | |
| from typing import Dict | |
| import numpy as np | |
| import pandas as pd | |
| def updrs4_fallback( | |
| pred_df: pd.DataFrame, | |
| train_df: pd.DataFrame, | |
| target_cols, | |
| mask_cols, | |
| mode: str = "none", | |
| ) -> pd.DataFrame: | |
| """Replace updrs_4 predictions with a population median or zero. | |
| This mirrors the observation from the top solutions that updrs_4 is mostly zero | |
| and is rarely measured in controls. It is a post-processing baseline, not a model. | |
| """ | |
| if mode in {None, "none", ""}: | |
| return pred_df | |
| if mode not in {"median", "zero"}: | |
| raise ValueError(f"Unknown updrs_4 fallback: {mode}") | |
| out = pred_df.copy() | |
| for tcol, mcol in zip(target_cols, mask_cols): | |
| if not tcol.startswith("y_updrs_4_"): | |
| continue | |
| horizon = int(tcol.rsplit("_", 1)[1]) | |
| if mode == "zero": | |
| value = 0.0 | |
| else: | |
| vals = train_df.loc[train_df[mcol] == 1, tcol].dropna() | |
| value = float(vals.median()) if len(vals) else 0.0 | |
| mask = (out["target"] == "updrs_4") & (out["horizon"] == horizon) | |
| out.loc[mask, "y_pred"] = value | |
| return out | |