google-research / timesfm

TimesFM (Time Series Foundation Model) is a pretrained time-series foundation model developed by Google Research for time-series forecasting.
https://research.google/blog/a-decoder-only-foundation-model-for-time-series-forecasting/
Apache License 2.0
3.02k stars 228 forks source link

is there a detailed runnable sample? #30

Open BurrowsWang opened 1 month ago

BurrowsWang commented 1 month ago

the sample code in "Usage" is too simple to understand, is there a more sophisticated case for the beginners like me to refer to.

yanghou2000 commented 1 month ago

User gabaid971 creates a jupyternotebook to run the model and compare its performance against several simple benchmarks (arima, random_forest, etc). Here is the link: https://github.com/gabaid971/ts-forecaster/blob/b28d63a41490fc1b7391145654f350d97eb90bfd/ts_forecaster.ipynb

AlexYoung757 commented 1 month ago

does it support multivariable

yanghou2000 commented 1 month ago

does it support multivariable

If i understand the code correctly, yes it supports multivariate predictions. If you use forecast_on_df, you can set the frequency through the freq arguments, where there is another function freq_map in this repo that you can check the allowed frequency and input name. The input should have columns:

A minimal example of input dataframe that has 3 multivaraite labels and each have two timestamps would be like this unique_id. ds y apple price 2024-01-01 5 apple price 2024-01-02 6 banan price 2024-01-01 3 banan price 2024-01-02 2 orange price 2024-01-01 3 orange price 2024-01-02 1

Please correct me if my understanding about the implementation is wrong

def forecast_on_df(
      self,
      inputs: pd.DataFrame,
      freq: str,
      forecast_context_len: int = 0,
      value_name: str = "values",
      model_name: str = "timesfm",
      window_size: int | None = None,
      num_jobs: int = 1,
  ) -> pd.DataFrame:
    """Forecasts on a list of time series.

    Args:
      inputs: A pd.DataFrame of all time series. The dataframe should have a
        `unique_id` column for identifying the time series, a `ds` column for
        timestamps and a value column for the time series values.
      freq: string valued `freq` of data. Notice this is different from the
        `freq` required by `forecast`. See `freq_map` for allowed values.
      forecast_context_len: If provided none zero, we take the last
        `forecast_context_len` time-points from each series as the forecast
        context instead of the `context_len` set by the model.
      value_name: The name of the value column.
      model_name: name of the model to be written into future df.
      window_size: window size of trend + residual decomposition. If None then
        we do not do decomposition.
      num_jobs: number of parallel processes to use for dataframe processing.