Class Signature
TimesfmModel class implements Google’s TimesFM, a decoder-only foundation model for time series forecasting with quantile predictions.
Initialization Parameters
Model configuration dictionary. Must include TimesFM-specific hyperparameters.
Hugging Face model repository ID for loading pre-trained checkpoints.
Custom checkpoint path (optional).
Configuration Parameters
Theconfig dictionary should contain TimesFM hyperparameters:
Forecast horizon length.
List of quantile levels for probabilistic forecasting (e.g., [0.1, 0.5, 0.9]).
Methods
finetune()
The dataset for finetuning. Use
get_data_loader() to obtain the dataloader.Whether to freeze the transformer layers during finetuning. When True, only the output projection layers are trained.
Learning rate for training.
Number of training epochs.
The finetuned model.
forecast()
Input time series data.
A tuple containing:
- Mean forecast of shape (# inputs, # forecast horizon)
- Full forecast (mean + quantiles) of shape (# inputs, # forecast horizon, 1 + # quantiles)
evaluate()
Dataset for evaluation. Call
get_data_loader() to get the dataloader.If True, return only metrics.
When
metric_only=True:Dictionary containing:mse: Mean Squared Errormae: Mean Absolute Errormase: Mean Absolute Scaled Errormape: Mean Absolute Percentage Errorrmse: Root Mean Squared Errornrmse: Normalized RMSEsmape: Symmetric Mean Absolute Percentage Errormsis: Mean Scaled Interval Scorend: Normalized Deviationmwsq: Mean Weighted Scaled Quantile Losscrps: Continuous Ranked Probability Score
metric_only=False:Tuple of (metrics, trues, preds, histories, quantiles):metrics: Dictionary of metrics (as above)trues: Ground truth valuespreds: Mean predictionshistories: Historical contextquantiles: Quantile predictions
plot()
Dataset for plotting. Use
get_data_loader() to obtain the dataloader.Additional keyword arguments forwarded to the visualization helper.
This method does not return a value. It displays visualizations.
Usage Example
Notes
- TimesFM is a decoder-only transformer model designed for zero-shot forecasting
- The model outputs both point forecasts (mean) and quantile predictions for uncertainty estimation
- When finetuning with
freeze_transformer=True, only the output layers are updated - Quantile predictions enable probabilistic forecasting and uncertainty quantification
- Data is automatically denormalized during evaluation if the dataset was normalized