TimesFM is a foundation model for time series from Google Research. Where a traditional forecasting workflow makes you choose a model family, fit it, and tune it per series, TimesFM does none of that: it was pretrained on a large corpus of time series, and it forecasts your series zero-shot — it reads the observed values as context and predicts the future in a single forward pass, the way a language model completes a sentence.
(Code in this vignette isn’t evaluated when the package is built, because it needs a local Python setup and a one-time weights download.)
One-time setup
TimesFM’s inference code is a Python package, which timesfm drives
through reticulate. install_timesfm() creates a dedicated
virtualenv (it needs Python >= 3.10 and will tell you if it can’t
find one) and installs the PyTorch backend:
The first forecast downloads the pretrained weights from the Hugging
Face Hub and caches them in ~/.cache/huggingface/. Once
cached, add HF_HUB_OFFLINE=1 to your
~/.Renviron to skip the Hub’s revalidation requests and
load straight from disk.
Forecasting
timesfm() takes the observed series — a numeric vector
or ts, oldest first — and a horizon:
fc <- timesfm(AirPassengers, horizon = 24)
fc“Fitting” happens inside the forward pass; there is nothing to train. The loaded model stays in memory, so repeated forecasts in a session are fast.
The result holds point forecasts and the deciles of the forecast distribution:
fc$mean # point forecasts, length 24
fc$quantiles # 24 x 9 matrix, columns q10 ... q90The deciles give you prediction intervals directly — q10
and q90 bound an 80% interval, q50 is the
median: