Examples¶
Forecasting jobs on real public data, from the first model to a decision, with TimeGym in the loop. Read them with their results on the examples page of the documentation, or run them here.
| Example | The job | What TimeGym showed |
|---|---|---|
| Weekly shop sales: from forecast to stock order | Restock 30 products of an online gift shop every four weeks | Why the usual regression loses to a plain average, which simpler forecaster fits, and that neither knows about Christmas |
| Spare parts: the best score goes to a forecast of zero | Decide how many of each slow-selling car part to hold for six months | The lowest average error belongs to a forecast of zero; a score in the parts counter's terms and the scorecard name the forecaster that keeps parts on the shelf |
| The Christmas order: five Decembers cannot pick the forecaster | Order a souvenir shop's Christmas stock three months ahead, with seven years of history | A straight line fitted in units forecasts the last two Decembers at half; target_transform=LogTransform() puts it level with the best; generated shops with a known kind of growth show what a five-December backtest can tell, what each choice costs and how much to order on top |
| Call center staffing: forecast again at ten o'clock | Plan a bank's call center agents half hour by half hour | What a newer forecast is worth: nothing from two weeks ahead to the evening before, 15% once it looks at how yesterday went, another 12% from the calls taken by 10:00; and counting rows to find "last week" costs 18% on a calendar with holidays |
| Train station riders: what is the weather worth, at best? | Decide whether a ridership forecast for 20 train stations needs a feed of weather forecasts | Told the weather that really came, the forecaster gains under 2% on weekdays and 8% on weekends, from 24% at one station to nothing at two; "tomorrow like today" keeps half; the same cases and scoring with one table added |
| Daily births: how much history should a forecast learn from? | Forecast births day by day for a roster drawn up four weeks ahead | The same forecaster with different look-backs on the same test days: the week learned from all history is 28% worse than from one year, the season needs three years, and a generated week with a known change separates the data from the method |
| Tomorrow's electricity demand: let the worst days say what is missing | Forecast tomorrow's demand, half-hour by half-hour | Which days a day-ahead forecast gets wrong, round by round: the weekday, then public holidays, then weather the data lacks |
| Solar farm output: a range for every half hour is not a range for the day | Give a range for a solar farm's energy over the whole of tomorrow | Forecasts made of samples go through the pipeline; the half-hour score cannot tell whole days from shuffled half hours and the two whole-day scores can; generated series with the true answer show when the gap opens and what 28 samples cost |
| River flow: checking the range, not only the forecast | Give a three-day range for a river's flow | A 90% range that holds on average but not month by month, the one argument that repairs it, and how far it fails when the river rises |
| Will it rain tomorrow? Score the forecast you already have | Give the chance of rain tomorrow in Sydney | Our best forecaster gains 11% on "it rains one day in three" and the weather service's published forecast 53%; why the forecaster that is right most often scores worst, and which days have no score |
| Tomorrow's temperature: which city should Sydney watch? | Forecast Sydney's high for the next three days | Another city's record helps: Melbourne cuts tomorrow's miss by 14%, Perth helps most for later days, Darwin makes it worse, and two cities give what eight give |
| Tomorrow's air in London: the gaps someone filled in for you | Forecast the next 24 hours of fine particles at 24 monitors | A table with its gaps filled in makes every forecast look a fifth better than it is and ranks the silent monitors as the easiest; cutting cases only where the answers were measured gives the real numbers |
| Flu season: the calendar knows the rhythm, not the peak | Forecast flu hospital admissions in 21 states up to four weeks ahead | The same run sorted by season and by part of the season: a forecaster that follows the calendar is ahead when the peak keeps its week and the worst when it comes late, and no forecast made four weeks before a peak saw more than 62% of it; generated seasons that repeat clear the forecaster, and telling it the peak week shows what is missing |
| The sunspot cycle: how far ahead is a forecast worth making? | Forecast a cycle eleven years ahead | A regression that leads for two years and adds nothing after, and how little room an irregular cycle leaves a cleverer model |
| El Niño: how far ahead depends on the month you ask | Forecast the Southern Oscillation Index nine months ahead and say which of those months to act on | "Seven months" on average hides two cases: a forecast that has to pass from April into May gains nothing, even one month ahead, and one that does not is still ahead at nine; checked on earlier years and on generated series with no seasons |
| The forest that cannot follow growth | Forecast next year's airline passengers | A random forest that passes its backtest cannot forecast a trend, and the textbook fix makes it worse elsewhere |
| You tried 50 models: is the winner real? | Choose a model for next year's patient numbers of 114 medical products | The backtest's winner leads by 0.2%, nine others cannot be told apart from it, a winning score flatters by about 4%, and the next year the winner comes tenth |
| Ready-made model or your own? Five products decide | Decide whether a pretrained model should replace the tuned forecasters for 114 medical products | The model scores 81 on the scorecard against 62 and 65 for ours and is 22% worse on the backtest average; each product's score shows five products carry the gap, generated series reproduce the error and measure when it happens, and three test years tell a guard from a fix that only fixed one year |
| A traffic jump: is this the new normal? | Three days into a jump in a page's views, forecast the next four weeks | The same forecasters on every week and on the alarm days give opposite orders; two scorecard rows name what a jump can do; a forecaster that learns the fade from earlier jumps beats all four |
| Site capacity: which forecast still works four weeks ahead? | Book a site's capacity four weeks ahead, with spare capacity on top | A generated weekly cycle catches a one-day slip the real data hides; the same weeks cut at five lead times show two forecasters level for next week and far apart for the job; the kept forecasts size the spare capacity |
| Bitcoin: finding out you have nothing | Forecast tomorrow's price | A 79% hit rate that came from one input reaching into the future; the honest model ties with yesterday's price |
| The S&P 500 next week: the direction and the size are different questions | Say something useful each Friday about the index's next week | No forecaster calls the direction better than "always up"; a 90% range that follows the last 26 weeks holds in crashes, where one built from all history held on 60% of the weeks of 2008 |
Run them¶
From a clone of the repository:
python -m pip install -e '.[examples]'
python -m jupyterlab examples
Every notebook reads a small sample committed in data/, so
it runs offline, and is saved with its outputs. One example also reads
forecasts that a large pretrained model made in advance, kept in
forecasts/. Installing the wheel alone does not
install these notebooks.
The data¶
example_data.py loads the datasets:
from example_data import load, about
sales = load("store-sales") # the committed sample
everything = load("store-sales", full=True) # downloads the public source once
print(about("store-sales")) # source, license and credit
data/README.md gives each dataset's source, license, credit
and checksums. python examples/example_data.py --check verifies the committed
samples, and --rebuild NAME writes one again from its source.
Add an example¶
Contributing lists the steps.
Terminal scripts¶
Two scripts from before the notebooks, still used by the tests:
quickstart.py: generate controlled cases and inspect a diagnostic report.reproduce_report.py: replay a saved report case for a supported built-in model.
python examples/quickstart.py
python examples/reproduce_report.py report.json --case-index 0
The README's figures are redrawn by
tools/readme_figures.py. The original example
notebook is preserved as
Quick Start (2021) at the v1.4.0 tag.