Time-Series Forecasting
Predict future values from history: demand, traffic, sales, load.
Typical projects
Three ways to build it
Starter
Pretrained forecasting model (Chronos / TimesFM) or ProphetZero-shot foundation models forecast without training; Prophet is simple and explainable.
Best for: No or little data, or new to ML
chronos-forecasting · Prophet · pandas
Standard
StatsForecast (AutoETS/AutoARIMA) + LightGBM with lag featuresFast, reliable statistical models plus a tree model for extra signals.
Best for: Some labeled data and Python experience
StatsForecast · MLForecast · LightGBM
Advanced
Global deep models (N-HiTS / TFT) across many seriesWhen you have thousands of related series, one global model learns shared patterns.
Best for: Lots of data and an experienced team
NeuralForecast · PyTorch · Ray
How success is measured
MAPE or MAE measured with backtesting over several past periods
The data you'll need
- You need a timestamp column and the value, ideally 2+ full seasonal cycles (e.g. 2 years for yearly patterns).
- Include known future events: holidays, promotions, price changes.
- Keep the timestamps regular (fill gaps explicitly).
Labeling
No manual labeling needed — the future values in your history are the labels.
Preparing the data
- Resample to a regular frequency
- Fill or flag missing periods
- Add calendar features (day of week, holiday)
- Never shuffle — always split by time
Start with a baseline
A seasonal naive forecast: 'same as the same day last week'. Surprisingly hard to beat.
Evaluating the model
- Rolling-origin backtesting
- Compare against the seasonal naive baseline
- Check prediction intervals actually contain ~80–90% of outcomes
Monitoring in production
- Forecast error each period
- Structural breaks (new store, pandemic-style shocks)
- Retraining on a schedule (weekly/monthly)
Common pitfalls
- Random train/test split leaks the future
- Ignoring holidays and promotions
Example code
CodeQuick start
# pip install chronos-forecasting pandas torch
import pandas as pd, torch
from chronos import BaseChronosPipeline
df = pd.read_csv("sales.csv", parse_dates=["date"])
pipe = BaseChronosPipeline.from_pretrained("amazon/chronos-bolt-small")
quantiles, mean = pipe.predict_quantiles(
context=torch.tensor(df["sales"].values), prediction_length=28,
quantile_levels=[0.1, 0.5, 0.9])
print(mean)CodeTrain your own model
# pip install statsforecast pandas
import pandas as pd
from statsforecast import StatsForecast
from statsforecast.models import AutoETS, SeasonalNaive
df = pd.read_csv("sales.csv", parse_dates=["date"])
df = df.rename(columns={"store_id": "unique_id", "date": "ds", "sales": "y"})
sf = StatsForecast(models=[AutoETS(season_length=7), SeasonalNaive(season_length=7)], freq="D")
cv = sf.cross_validation(df=df, h=28, n_windows=4) # backtesting
print(cv.head())
forecast = sf.forecast(df=df, h=28)
forecast.to_csv("forecast.csv", index=False)