A forecast that scored near-perfect because it could see the answer
The first PricePoint forecaster had target leakage. Rebuilt without it, the model loses to repeating the last price.
£0.053 vs £0.023model error vs repeating the last price, next day
Written up , revised
Symptom
The first PricePoint forecaster reported a held-out R² in the high 0.9s on UK supermarket prices, and I put the result on the site. Over 95 days, one product’s price barely moves, so nearly any model that sees yesterday’s price scores well on R². Nothing I had run said whether the model beat simply repeating yesterday’s price.
Hypothesis
Either the model was good, or a feature contained the target. The second is cheaper to check, so I checked it first. I also scored the naive forecast on the same rows, which I should have done before publishing anything.
Evidence
price_lag_1d + price_diff_1dequalled the price on 100% of held-out rows. The diff was today’s price minus the previous row’s, so adding the lag back rebuilds today’s price.- Every rolling mean, standard deviation, maximum and minimum over 7, 14 and 30 rows included the current row.
price_vs_market_avgsubtracted other retailers’ same-day prices from today’s price, so it carried today’s price too.- 41.5% of rows shared product, retailer and date with another row. Series were keyed on product and retailer, which merged pack sizes, so the “previous row” was often a different listing from the same day.
The leakage test I already had passed. It checked one thing, that the same-day market average left out the row’s own retailer.
Root cause
Windows included day t, and the series key was too coarse to say what “previous” meant. I had one test for one leak and read its green result as covering all of them.
Both mistakes were older than the model. When I moved the feature code from pandas to Polars in August, the rewrite was tested for exact equivalence with the pandas version, including on series with date gaps, and it passed. That test carried both leaks across unchanged (see the entry on the August benchmark).
Fix
I wrote the method down before training anything, in docs/forecast_leak_fix.md. The series key became one listing, retailer and product name. Every price feature uses only that listing’s earlier observations. Market features use other retailers’ previous prices, leaving the row out. I kept the same split (final 7 days held out) and the same LightGBM settings, tuned nothing on the test set, and scored it once. Intervals come from a bootstrap that resamples whole listings, 1,000 times, because days within a listing are not independent.
The earlier figure is withdrawn everywhere on the site.
The model does not beat repeating the last price. A second model that predicts the change from the last price also loses on MAE, at one day (£0.0430 against £0.0232) and at seven (£0.1853 against £0.1346). It does rank which prices will move: AUC 0.833, against 0.559 for a simple rule. The live dashboard now shows the naive baseline, and every headline number on the site sits next to the cheapest method it has to beat.
Regression guard
tests/data_contracts/test_no_target_leakage.py now perturbs the target day’s prices and asserts that no feature changes, and asserts that lag plus diff cannot rebuild the target. A feature that reads the day it predicts fails the first test, whichever column it arrives through.
Status
Closed for the leak, open for the model. No PricePoint model beats repeating the last price. The seven-day test week had already been scored by the earlier model, so it is not an untouched window, and next-day 90% intervals cover only 19.5% of the prices that moved. The seven-day experiment files are in my working copy but not yet pushed to GitHub, and docs/forecast_leak_fix.md sits in a git-ignored folder, so neither is linked here.