
Software
Bakery Demand Forecast (client under NDA)
LightGBM quantile forecasts of daily pastry sales for six shops, three days ahead, with an editable bake sheet for the chef. It beat the best simple baseline in a 7-month walk-forward backtest (25.1% vs 27.9% WAPE) and documents where it still fails.
- Time-series forecasting
- LightGBM
- Quantile regression
- Backtesting
- Python
- pandas
- Next.js
- CI/CD
- sales rows: 6 shops, 8 pastries, 16 months
- 1.1M
- WAPE for the model, against 27.9% for the best simple baseline
- 25.1%
- of shop-pastry-days covered when baking the P75 forecast
- 80%
- on Christmas Eve, a day the model had never seen
- 55% low
All from the walk-forward backtest, October 2024 to April 2025. WAPE is weighted absolute percentage error for one shop, one pastry, one day. Lower is better.
Forecasting what a bakery should bake, three days ahead. The bakery sets its daily pastry quantities, called pars, by hand and changes them every few months. I built a system that forecasts how many of each breakfast pastry each shop will sell three days ahead, turns that into a bake sheet the pastry chef can edit, and reports how accurate it is and where it fails.
It is a working prototype built from one 16-month data export. I presented it to the client as a first version, along with the list of data that would improve it. It is not running in production.
The shops in the screenshots are renamed Shop A to Shop F, because the client data is under NDA.
01
Spec
| Lane | Software |
|---|---|
| Status | In progress |
| Role | Solo project: data cleaning, model, backtest, frontend and CI |
| Client | A bakery group with six shops. Client data is under NDA. |
| Data | One 16-month export, 1.1M sales rows, 6 shops, 8 breakfast pastries |
| Model | LightGBM. Poisson objective for the mean, quantile models for P50, P75 and P90. |
| Validation | Walk-forward backtest by month, October 2024 to April 2025, with a leakage test in CI |
| Stack | Python, LightGBM, pandas, Next.js, Cloudflare Pages |
02
Problem
A par that changes every few months
A baker has to decide how many croissants and morning buns each shop gets before anyone has walked in. Too many and they are left over. Too few and they run out.
The bakery handles this with a par for each pastry, set by hand and changed every few months. I wanted a number for each shop, each pastry and each day, ready three days ahead, that the chef could still overrule.
03
Data
The data, and what was wrong with it
I had four CSV exports from the client's FileMaker database: sales, end-of-day counts, store orders and products. I added daily weather from Open-Meteo. Most of the early work was making the files usable.
| File format | No header rows, and lines ended with a bare carriage return |
|---|---|
| Product names | Inconsistent, so everything keys on product ID |
| Shop identifiers | The sales and inventory files used different ones, which had to be mapped |
| End-of-day counts | About 25% of records were unsubmitted and had to be excluded |
| Target | Daily units per shop and pastry from the point-of-sale system, with closed days dropped |
04
Model
Features, learner, and why quantiles
Every feature is something known three days before the target day. The same-weekday lags are at 7, 14, 21, 28 and 364 days. The rest are a 4-week same-weekday mean, 7-day and 28-day rolling means shifted by the horizon, a store traffic lag, the calendar, holiday flags, days until the next holiday, and daily maximum temperature and precipitation.
The learner is LightGBM. One model with a Poisson objective predicts the mean. Three separate quantile models predict P50, P75 and P90, forced monotone so they never cross.
A baker does not want the average. They want to choose how often they are willing to run out. So the quantiles become the bake sheet's Lean, Balanced and Generous settings. The screen shows each setting's measured coverage from the backtest, not its nominal level: P50 covered 62% of shop-pastry-days, P75 covered 80% and P90 covered 90%.
On every merge, in GitHub Actions
- Rebuild the forecast from source datatests, including the leakage testlintbuilddeploy to Cloudflare Pages
Source data
Sales, end-of-day counts, store orders and products as CSV exports, plus daily weather.
Then, clean and join on product ID:
1Daily panel
Units per shop, pastry and day. Closed days dropped.
Unsubmitted end-of-day records are excluded.
Then, only data from three or more days before the target day:
2Features
Lags, rolling means, calendar, holidays, weather.
A test asserts no feature uses data from after the forecast date.
Then, LightGBM:
3Mean
Poisson objective.
4Quantiles
P50, P75 and P90, forced monotone.
5Backtest
Walk-forward by month, against two baselines.
Bake sheet and track record
A static Next.js site. Lean is P50, Balanced is P75, Generous is P90.
The chef can change any number.
05
Testing
How I tested it
The backtest walks forward by month. For each test month, I train only on data up to three days before the month starts, then predict the whole month. There are no random splits, because a random split lets the model see the future.
I compared the model with two rules a person could use to set pars: the same day last week, and the average of the last four same weekdays. The metric is WAPE at the level of one shop, one pastry, one day.
| Test period | Same day last week | 4-week same-weekday average | My model |
|---|---|---|---|
| All test months | 33.8% | 27.9% | 25.1% |
| Ordinary days (holiday weeks excluded) | n/a | 26.5% | 23.7% |
| December 2024 | 44.7% | 32.4% | 28.4% |
By month, the model's WAPE was 24% in October, 27% in November, 28% in December, 27% in January, and 23% in February, March and April. It beat both baselines in all seven months. October was narrow: 23.9% against 24.4%.
A leakage test guards the result. It is an integration test on the real panel that asserts no feature uses data from after the forecast date. It runs in CI on every pull request, along with a full rebuild of the pipeline.
One decision came straight out of the backtest. I added a day-of-year feature, and December got worse than the simple baseline, at 40.6% WAPE. With under two years of history, every test month contains day-of-year values the model never trained on. Removing the feature brought December to 28.4% and moved no other month by more than half a point.
I also compared the P75 forecast with what the shops actually ordered over the same days, for 4 shops and 5,486 shop-pastry-days. Baking the P75 forecast used 4% fewer pieces, left 20% unsold instead of 26%, and missed 6% of sales instead of 9%. It ran short on more days, 21% against 17%, but by fewer pieces. This assumes the recorded order equals what was baked, which the client has not confirmed.
06
Failures
Where it fails, and why
Holidays it has never seen. The data starts in January 2024, so the model was tested on its first Thanksgiving and its first Christmas. It was 52% low on the day before Thanksgiving and 55% low on Christmas Eve. Holiday weeks were 9% of test days but 16% of total error. Easter shows what one prior example does: the previous Easter was in the training data, and Easter Saturday 2025 was forecast within 5%, 1,445 forecast against 1,380 sold.
Sold-out days. 43% of end-of-day counts found the pastry sold out, and 66% for the top item. So sales understate demand, and a model trained on sales learns to under-bake. The model does not yet correct for sold-out days. That is the next modeling task.
Promotions nobody told it about. Two unannounced promotion days sold 4x the forecast, 1,037 against 253. The spike then inflated the same-weekday lag features for the following four weeks.
The noise floor. A shop sells about 17 of a given pastry a day, so even a perfect forecast of the mean would miss by about 18% WAPE. The realistic gap to close is 24% to 18%, not 24% to 0%.
Sales are not demand. On a day the pastry sold out, the data shows what was baked, not what people wanted.
07
Product
The tool the chef would use
The product is a static Next.js site. On the bake sheet you pick the day, pick the buffer and pick the shop. Every number is editable, and the sheet exports to CSV and prints.
The track record page shows forecast against actual by shop and pastry. I also wrote a plain-language page for the client covering accuracy, the failure cases and the data needed to fix each one. Several of the images on this page are sections of it.
08
Next
What I would do next
First, correct for sold-out days, using the end-of-day counts to estimate the demand that sales hide. Until then the model inherits the shortage it was trained on.
Second, get more history, so the model has seen Thanksgiving and Christmas before it is asked to forecast them. Third, get a list of promotion dates, so a promotion is a feature instead of a surprise that distorts the next four weeks.
09
Footprint
Stack and footprint
| Model | Python, pandas, LightGBM |
|---|---|
| Product | Next.js static site, TypeScript and React |
| Hosting | Cloudflare Pages, behind a password gate that fails closed |
| CI | GitHub Actions rebuilds the forecast from source data, runs tests, lints, builds and deploys on every merge |
| Size | About 600 lines of Python and about 1,500 lines of TypeScript and React |
| Team | Solo |
10
Links
Private repo, client data under NDA. Happy to walk through the code in an interview.