Getting Started with TimesFM: A Guide to Time Series Forecasting

May 16, 2024 | Educational

In the rapidly evolving world of AI, Google Research has presented TimesFM, a revolutionary pretrained model for time-series forecasting. This guide will walk you through the installation, usage, and troubleshooting aspects of using TimesFM, ensuring you harness its power for your forecasting needs.

Installation

To get started with TimesFM, you need to install the required library. You can find the installation instructions in the GitHub repository. Follow the steps carefully to set everything up seamlessly.

Using TimesFM

Model Initialization

To use the TimesFM model, you first need to initialize it and load a checkpoint. Here’s how to do it:

import timesfm

tfm = timesfm.TimesFm(
    context_len=context,
    horizon_len=horizon,
    input_patch_len=32,
    output_patch_len=128,
    num_layers=20,
    model_dims=1280,
    backend=backend,
)

tfm.load_from_checkpoint(repo_id='google/timesfm-1.0-200m')

In this example:

  • **context_len**: Maximum length of your input data (up to 512 time points).
  • **horizon_len**: The predicted length of your output which can be set to any value based on the forecasting task.
  • **input_patch_len** and **output_patch_len**: Define the size of the input and output sequences.
  • **num_layers** and **model_dims**: Represent the architecture specifics of your model.

Performing Inference

TimesFM provides APIs to forecast from either array inputs or pandas dataframes. Ensure you follow these methods correctly:

  • Utilize tfm.forecast() for array inputs.
  • Utilize tfm.forecast_on_df() for pandas dataframe inputs.

The model expects two key inputs during forecasting:

  1. Time series contexts
  2. Frequency indicators

The frequency indicators are categorized as follows:

  • 0: High frequency (daily granularity)
  • 1: Medium frequency (weekly/monthly)
  • 2: Low frequency (quarterly/yearly)

Code Explanation with Analogy

Think of the TimesFM model like a chef preparing a gourmet meal.

  • The context_len represents the ingredients – the more fresh ingredients you have prepared (up to a maximum), the better your dish can turn out.
  • The horizon_len can be likened to the time it takes to cook – you can choose to take a quick-stir fry or a slow roast based on your requirements.
  • The input_patch_len and output_patch_len are like chopping techniques – finely diced for subtle integration or broader cuts for bulk flavor incorporation.
  • Your model’s structure (layers and dimensions) is akin to the chef’s kitchen setup – the more sophisticated the tools available, the better the potential outcomes, while still respecting the individual quirks of the chef (model).

Troubleshooting

As you dive into using TimesFM, you may encounter some challenges. Here are some troubleshooting tips to help you along the way:

  • **Model Not Loading**: Ensure that your checkpoint path is correct and matches the required format.
  • **Input Length Errors**: Verify that your input data meets the required context length. Remember that padding or truncation should be handled by the inference code.
  • **Frequency Input Issues**: Double-check that you are using the correct categorical indicators for the frequency settings as mentioned above.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox