fix(#978): train-only detrend + Almon distributed-lag regression #1040
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#1040
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/978-almon-adl-regression"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
REOPENED #978 (951-B §9.6).
PART A (leakage fix): backtest --detrend fit ln(units) trend over train+test then split -> test data shaped the detrend -> inflated OOS. _detrend_log now fits trend on TRAIN only + projects (a,b) point-in-time to test. Synthetic-verified leaky != train-only.
PART B (DoD): new regression.py — Almon polynomial distributed-lag (deg2, key_rate lags 0..6) via OLS + manual Newey-West HAC (NO statsmodels) + per-district {best_lag_months,coef,r2,n,per_lag_coef,hac_se} + fallback gate (n<30/R2<0.1/sumbeta>=0) + §9.6 phrase. 31 synthetic-recovery tests. ADVISORY, shipped standalone, wiring DEFERRED (documented) to protect live consumers.
125+31 tests green, ruff clean. Prod backtest re-run pending (couldn't run from worker sandbox). Refs #978
REOPENED 951-B §9.6. PART A: fix look-ahead leakage in backtest_rate_sensitivity --detrend. The ln(units) trend was fit over train+test then split, so test data shaped the detrend and inflated the OOS hit-rate. _detrend_log now takes fit_n; backtest_tier fits the trend on TRAIN months only (same split evaluate_oos uses) and projects (a,b) point-in-time onto test. Default fit_n=None preserves prior behaviour. PART B (DoD): new app/services/forecasting/regression.py — Almon polynomial distributed-lag (deg 2) of Δln(district demand) on Δkey_rate lags 0..6 via OLS-on-Almon-regressors (numpy lstsq) + per-lag reconstruction + manual Newey-West HAC SEs (NO statsmodels). Output {best_lag_months, coef=long-run multiplier, x_pct, r2, n, per_lag_coef, hac_se,...}; gate mirrors _elasticity_coef (n<30 OR R²<0.1 OR Σβ≥0 → fallback); §9.6 phrase from the lag shape. ADVISORY, shipped standalone (integration point documented), NOT wired — protects the live compute_rate_sensitivity consumers. 125+31 tests (synthetic known-lag recovery, HAC computed/differs-from-OLS, fallback gating, no-leakage detrend). ruff clean. Refs #978