File size: 1,238 Bytes
04ae9bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | """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
|