fix(ml): serve the forecast rain the model was trained with
CI / Format & lint (push) Successful in 24s
CI / Test suite (push) Successful in 48s
Docs / Validate documentation (push) Successful in 24s
Security / Dependency vulnerabilities (push) Successful in 2m20s
Security / Static analysis (push) Successful in 21s
Security / License report (push) Successful in 1m40s
CI / Format & lint (push) Successful in 24s
CI / Test suite (push) Successful in 48s
Docs / Validate documentation (push) Successful in 24s
Security / Dependency vulnerabilities (push) Successful in 2m20s
Security / Static analysis (push) Successful in 21s
Security / License report (push) Successful in 1m40s
build_features cut the rain series to the gauge grid before the forward sum, and the grid ends at the newest reading, so the row every live forecast is made from had rain_fc24 = NaN. Training and all evaluations had the real Open-Meteo forecast there. The forward sum now runs over the grid extended by 24 h; earlier rows are unchanged. Harness (new opt-in variant rise_rain_fc24_missing = rise_rain with rain_fc24 blanked on test rows, five folds, --from-cache): P.1 and P.103 nearly unaffected, P.21 false alarms 10 -> 5 and MAE 0.232 -> 0.215 with the fix. Write-up in docs/FLOOD_FORECASTING.md section 5; results in models/eval_2026-10-18_fc24.json. Also: HII mirror rows in one hour now resolve to the latest reading via a stable sort on the raw time (was an unstable sort on the floored hour, i.e. row-order dependent). Needed for an exact Rust port.
This commit is contained in:
1 parent
64c5b02e06
commit
6d4beae65a
6 files changed
+876
-6
No files matched your search
+19
-2
@@ -209,6 +209,7 @@ def _hours_since_observed(mask_col: pd.Series) -> pd.Series:
|
||||
|
||||
|
||||
RAIN_FEATURES = ("rain_6h", "rain_24h", "rain_72h", "rain_fc24")
|
||||
FORWARD_RAIN_H = 24 # rain_fc24 window
|
||||
|
||||
DAM_FEATURES = ("dam_storage_pct", "dam_storage_pct_d3", "dam_inflow", "dam_outflow")
|
||||
# Stations hydrologically downstream of the Mae Ngat confluence (Ping mainstem
|
||||
@@ -297,9 +298,25 @@ def build_features(
|
||||
cols["rain_6h"] = r.rolling(6, min_periods=1).sum()
|
||||
cols["rain_24h"] = r.rolling(24, min_periods=1).sum()
|
||||
cols["rain_72h"] = r.rolling(72, min_periods=1).sum()
|
||||
# forward sum over (t, t+24]: shift(-1) starts the window at t+1
|
||||
# forward sum over (t, t+24]: shift(-1) starts the window at t+1.
|
||||
# Computed on the grid extended by the 24 h after its last row: the
|
||||
# last row is the one serving predicts from, and cutting the rain
|
||||
# series to the grid made its forecast rain always NaN (unlike every
|
||||
# training row since 2021). Earlier rows keep their values.
|
||||
future = (
|
||||
pd.date_range(idx[-1], periods=FORWARD_RAIN_H + 1, freq="h")[1:]
|
||||
if len(idx)
|
||||
else idx[:0]
|
||||
)
|
||||
r_ext = rain.reindex(idx.append(future))
|
||||
cols["rain_fc24"] = (
|
||||
r.shift(-1).iloc[::-1].rolling(24, min_periods=1).sum().iloc[::-1]
|
||||
r_ext.shift(-1)
|
||||
.iloc[::-1]
|
||||
.rolling(FORWARD_RAIN_H, min_periods=1)
|
||||
.sum()
|
||||
.iloc[::-1]
|
||||
.iloc[: len(idx)]
|
||||
.set_axis(idx)
|
||||
)
|
||||
|
||||
if dam is not None and station in DAM_STATIONS:
|
||||
|
||||
Reference in new issue
Block a user