Overview

7 Deterministic forecasting with TimesFM

This chapter introduces deterministic (point) forecasting and TimesFM, a foundation model from Google Research that outputs single-value forecasts instead of full predictive distributions. The authors contrast this approach with probabilistic models used earlier in the book, noting that while point forecasts simplify downstream use and suit planning scenarios, they do not quantify uncertainty and therefore are not appropriate for tasks like anomaly detection. Although TimesFM can emit experimental quantiles, these are not calibrated and should not be relied upon for interval-based decisions. The chapter focuses on TimesFM’s architecture and pretraining protocol, shows how to apply it in zero-shot mode, and explores how to incorporate exogenous features.

Architecturally, TimesFM is a decoder-only Transformer that processes non-overlapping input patches and is trained to produce longer output patches than inputs, reducing the number of autoregressive steps required for long horizons. Residual MLP blocks embed patched inputs and map Transformer outputs back to forecasts, with positional encodings added as in standard Transformers. A random input-patch masking strategy during pretraining enables handling varied context lengths. The model is trained with mean squared error, and was pretrained on a massive corpus exceeding 380 billion points, dominated by web traffic data (e.g., Wiki Pageviews, Google Trends), plus synthetic series (including ARMA, seasonal sinusoids, trends, step functions). Practical constraints include maximum context lengths (initially up to 512 steps, extended to 2048 in a later 500M-parameter release), autoregressive generation beyond the 128-step output patch, substantial memory needs (around 16GB RAM), and open-source availability primarily for the largest checkpoints.

In practice, TimesFM is straightforward for zero-shot forecasting via a DataFrame API that expects standardized column names and a frequency setting; cross-validation must be implemented manually. On a weekly retail example, zero-shot performance was competitive—outperforming Moirai and approaching fine-tuned baselines—though it struggled with abrupt level shifts. Exogenous features are supported outside the core model via a simple ridge regression wrapper that combines covariate effects with TimesFM’s forecasts (either modeling the target first and covariate-driven residuals second, or vice versa). This requires future covariate values; in the example, a holiday indicator helped capture peaks but degraded overall error metrics. Fine-tuning presently demands JAX expertise and custom training loops, and given its deterministic nature (and uncalibrated quantiles), TimesFM is not suitable for anomaly detection.

Architecture of TimesFM. The input series is patched and set to a residual block that maps the input patches to a vector. The residual block is simply a multilayer perceptron with one hidden layer and a skip connection. The output vector is added to positional encoding and sent to the decoder-only Transformer. The output of the Transformer is sent to another residual block which returns a sequence of predicted values.
In TimesFM, the output patch is longer than the input patch. That way, the model performs less autoregressive steps when forecasting longer horizons, which results in better performance.
Input patch masking strategy during the training phase of TimesFM. The input patch is randomly masked, leaving at least one time step. That way, the model is trained to output an output patch with a varying input length.
Focusing on the decoder-only portion of TimesFM. The decoder is made of many decoder layers, each using multi-headed attention.
Zero-shot predictions of the weekly sales for each store. The shaded area shows the 90% prediction interval, but it comes from experimental quantiles that were not calibrated, so it may not be valid.
Predictions obtained from cross-validation with TimesFM. Note that the shaded area represents a 90% prediction interval obtained from experimental quantiles that were not calibrated, so it may not be valid.
There are two options for handling exogenous features in TimesFM. In option 1, we forecast the target itself first with TimesFM, then model the residuals with the exogenous features, and add both predictions for the final forecast. In option 2, we first model the exogenous features using linear regression, then TimesFM forecasts the residuals, and both outputs are added for the final predictions.
Comparing the forecasts obtained with and without covariates. We notice that by using covariates, the model predicts future peaks in sales.
MAE and sMAPE for forecasting with covariates and without covariates. Lower is better. Here, using covariates results in less accurate forecast from TimesFM.

Summary

  • TimesFM is a deterministic foundation model developed by Google Research. It uses a decoder-only Transformer for point forecasting.
  • The model is open-source and free to use. However, only the largest version is available.
  • It supports exogenous features by using an external linear regression algorithm.
  • Since it is deterministic, it cannot perform anomaly detection.
  • Fine-tuning the model requires knowledge of JAX, making it inaccessible to practitioners unfamiliar with the technology.

References

FAQ

What is deterministic forecasting, and why does TimesFM use it?Deterministic (point) forecasting outputs a single value per future time step, without a probability distribution. TimesFM is a deterministic foundation model, making it well suited when you only need point forecasts for planning and don’t require uncertainty estimates or intervals.
How does TimesFM’s architecture work?TimesFM uses a decoder-only Transformer. The input series is patched (contiguous, non-overlapping chunks), embedded via residual blocks, summed with positional encoding, and passed through stacked decoder layers with multi-head attention. Another residual block maps the Transformer outputs to predicted values.
Why are TimesFM’s output patches longer than the input patches?Training with longer output patches reduces the number of autoregressive steps needed for long horizons, improving accuracy. For example, with input patch length 32 and output patch length 128, forecasting 256 steps requires only two autoregressive steps instead of eight.
What input lengths and horizons are supported?The original release supports up to 512 input steps (context), while the latest checkpoint supports up to 2048. context_len must be a multiple of 32, and longer inputs are truncated. If the requested horizon exceeds the output patch length (128), TimesFM forecasts recursively; shorter horizons are truncated from the output patch.
How was TimesFM pretrained (loss and data)?TimesFM minimizes mean squared error (MSE). It was trained on a very large corpus (over 207M series and 380B+ points), dominated by web traffic data (e.g., Wiki Pageviews), plus Google Trends, M4, and synthetic series (ARMA, seasonal sinusoids, trends, steps). Roughly 80% of samples are real-world and 20% synthetic. Training used input patches of 32 and output patches of 128.
What versions and hardware requirements should I expect?TimesFM was released in multiple sizes, but only the largest checkpoints are public (e.g., 200M params in v1.0 and 500M in v2.0). Expect at least 16 GB of RAM to load the model and dependencies. Some dependencies install more smoothly on Linux; many users run it in Google Colab.
How do I run zero-shot forecasts on a pandas DataFrame?Rename the date column to ds and the ID column to unique_id, then call forecast_on_df with inputs, freq, and value_name. Only context_len and horizon_len typically change; parameters like num_layers and per_core_batch_size are fixed. Frequencies map internally to categories: high (S/MIN/H/D/B → 0), medium (W/M → 1), low (Q/Y → 2). The method returns a DataFrame of predictions.
Can TimesFM produce prediction intervals or detect anomalies?The model exposes experimental, non-calibrated quantiles (up to a 90% interval). Because TimesFM is deterministic and the intervals aren’t calibrated, it isn’t suitable for reliable uncertainty quantification or anomaly detection.
Does TimesFM support multivariate inputs or exogenous features?TimesFM is univariate; each series is forecast independently. Exogenous variables are supported via an external ridge/linear regression that combines covariates with TimesFM’s fit. Two modes are available (fit TimesFM first or fit exogenous regression first). Covariates must be known into the future and can be dynamic/static and numerical/categorical. Results are dataset-dependent.
How do I do cross-validation and fine-tuning with TimesFM?There’s no built-in cross-validation; implement a rolling/expanding window loop that slices the DataFrame and calls forecast_on_df, then aggregate and score (e.g., MAE, sMAPE). Fine-tuning is possible but requires JAX and custom training/batching code, and documentation is sparse.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Time Series Forecasting Using Foundation Models ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Time Series Forecasting Using Foundation Models ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Time Series Forecasting Using Foundation Models ebook for free