feat: hgb-v2 — regression heads predict rise, recovering flood warning lead
CI/CD Pipeline - Northern Thailand Ping River Monitor / Build Docker Image (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Integration Test with Services (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Deploy to Staging (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Deploy to Production (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Performance Test (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Code Quality (push) Successful in 15s
Documentation / Validate Documentation (push) Failing after 9s
Documentation / Generate API Documentation (push) Successful in 8s
Documentation / Build Sphinx Documentation (push) Successful in 17s
CI/CD Pipeline - Northern Thailand Ping River Monitor / Cleanup (push) Successful in 1s
CI/CD Pipeline - Northern Thailand Ping River Monitor / Test Suite (3.11) (push) Failing after 28s
Documentation / Documentation Summary (push) Successful in 2s
CI/CD Pipeline - Northern Thailand Ping River Monitor / Build Docker Image (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Integration Test with Services (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Deploy to Staging (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Deploy to Production (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Performance Test (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Code Quality (push) Successful in 15s
Documentation / Validate Documentation (push) Failing after 9s
Documentation / Generate API Documentation (push) Successful in 8s
Documentation / Build Sphinx Documentation (push) Successful in 17s
CI/CD Pipeline - Northern Thailand Ping River Monitor / Cleanup (push) Successful in 1s
CI/CD Pipeline - Northern Thailand Ping River Monitor / Test Suite (3.11) (push) Failing after 28s
Documentation / Documentation Summary (push) Successful in 2s
Rolling-origin evaluation (5 monsoon folds x 4 variants, P.1 + P.103; results in models/eval_variants.json) showed the absolute-level target alerting AT the crossing on essentially every event, while the rise target (future max - current level, level added back at serving) gives +6h on the hard 2024 crossings, +45h in 2025, fewer false alarms than weighted/quantile variants, and ~11% better MAE. Weighted and quantile variants rejected: more false alarms, no Brier-score calibration gain. Ported to production: train.py fits rise in both eval and refit passes (sigma/metrics computed in absolute space), bundles stamped hgb-v2 with regression_target='rise', predict.py adds the level back for v2 and stays compatible with v1 bundles, backtest_render.py mirrors the same math. Regenerated backtest charts: 2024 first alert 11:00 24 Sep (6h BEFORE the 17:00 crossing, was 18h after), 2025 alert 45h ahead, and the record-peak underprediction is gone (rise models can exceed the training max). The >=12h acceptance gate still fails honestly at +6h — closing that needs rainfall inputs. New P.1 MAE 5.0/7.2/9.4 cm at 6/12/24h; docs updated throughout.
This commit is contained in:
@@ -46,14 +46,23 @@ RED = "#d9534f"
|
||||
|
||||
|
||||
def fit_backtest_model(df_long: pd.DataFrame, train_end: str):
|
||||
"""Train the 24 h regression + warning heads on rows <= train_end only."""
|
||||
X, Y, _meta = features.build_matrix(df_long, STATION, (HORIZON,))
|
||||
"""Train the 24 h regression + warning heads on rows <= train_end only.
|
||||
|
||||
Mirrors the deployed hgb-v2 pipeline: the regression head learns the RISE
|
||||
over the current level (rolling-origin evaluation 2026-08-12 showed this
|
||||
moves first-alert leads from ~0 h to +6..+46 h); label statistics are
|
||||
bounded to the training cutoff.
|
||||
"""
|
||||
X, Y, _meta = features.build_matrix(
|
||||
df_long, STATION, (HORIZON,), stats_end=train_end
|
||||
)
|
||||
train_mask = X.index <= pd.Timestamp(train_end)
|
||||
X_train, Y_train = X.loc[train_mask], Y.loc[train_mask]
|
||||
|
||||
max_col, warn_col = f"max_level_{HORIZON}", f"exceed_warn_{HORIZON}"
|
||||
reg_rows = Y_train[max_col].notna()
|
||||
reg = _make_regressor().fit(X_train.loc[reg_rows], Y_train.loc[reg_rows, max_col])
|
||||
rise = Y_train.loc[reg_rows, max_col] - X_train.loc[reg_rows, "level"]
|
||||
reg = _make_regressor().fit(X_train.loc[reg_rows], rise)
|
||||
warn_rows = Y_train[warn_col].notna()
|
||||
clf = _make_classifier().fit(
|
||||
X_train.loc[warn_rows], Y_train.loc[warn_rows, warn_col].astype(int)
|
||||
@@ -70,7 +79,8 @@ def event_series(df_long, X, reg, clf, window_start: str, window_end: str):
|
||||
|
||||
Xw = X.loc[window_start:window_end]
|
||||
forecasts = pd.DataFrame(index=Xw.index)
|
||||
forecasts["pred_max"] = reg.predict(Xw)
|
||||
# reg predicts the rise; add the current level back (as serving does)
|
||||
forecasts["pred_max"] = reg.predict(Xw) + Xw["level"].to_numpy()
|
||||
# Belt-and-braces probability: the classifier OR the regression-sigmoid,
|
||||
# whichever is more alarmed. The classifier alone proved unreliable on
|
||||
# out-of-distribution extremes (silent on the 2024 record flood).
|
||||
|
||||
Reference in New Issue
Block a user