The ML.FORECAST function

This document describes the ML.FORECAST function, which you can use to forecast a time series based on a trained ARIMA_PLUS or ARIMA_PLUS_XREG model.

Syntax

# ARIMA_PLUS models:
ML.FORECAST(
  MODEL `project_id.dataset.model`
    STRUCT(
      [, horizon AS horizon]
      [, confidence_level AS confidence_level]))

# ARIMA_PLUS_XREG model:
ML.FORECAST(
  MODEL `project_id.dataset.model`
    { TABLE `project_id.dataset.table` | (query_statement) }
    STRUCT(horizon AS horizon, confidence_level AS confidence_level))

Arguments

ML.FORECAST takes the following arguments:

  • project_id: Your project ID.
  • dataset: The BigQuery dataset that contains the model.
  • model: The name of the model.
  • horizon: an INT64 value that specifies the number of time points to forecast. The default value is 3, and the maximum value is the value of the HORIZON option specified in the CREATE MODEL statement for time-series models, or 1000 if that option isn't specified. When forecasting multiple time series at the same time, this parameter applies to each time series.

  • confidence_level: a FLOAT64 value that specifies percentage of the future values that fall in the prediction interval. The default value is 0.95. The valid input range is [0, 1).

  • table: The name of the input table that contains the features.

    If table is specified, the input column names in the table must match the column names in the model, and their types should be compatible according to BigQuery implicit coercion rules.

    If there are unused columns from the table, they are ignored.

  • query_statement: The GoogleSQL query that is used to generate the features. See the GoogleSQL query syntax page for the supported SQL syntax of the query_statement clause.

    If query_statement is specified, the input column names from the query must match the column names in the model, and their types should be compatible according to BigQuery implicit coercion rules.

    If there are unused columns from the table, they are ignored.

Output

ML.FORECAST returns the following columns:

  • time_series_id_col or time_series_id_cols: a value that contains the identifiers of a time series. time_series_id_col can be an INT64 or STRING value. time_series_id_cols can be an ARRAY<INT64> or ARRAY<STRING> value. Only present when forecasting multiple time series at once. The column names and types are inherited from the TIME_SERIES_ID_COL option as specified in the CREATE MODEL statement.
  • forecast_timestamp: a TIMESTAMP value that contains the timestamps of a time series.
  • forecast_value: a FLOAT64 value that contains the average of the prediction_interval_lower_bound and prediction_interval_upper_bound values.
  • standard_error: a FLOAT64 value that contains the amount of variability in the estimated results.
  • confidence_level: a FLOAT64 value that contains the confidence_level value you specified in the function input, or 0.95 if you didn't specify a confidence_level value. It is the same across all rows.
  • prediction_interval_lower_bound: a FLOAT64 value that contains the lower bound of the prediction interval for each forecasted point.
  • prediction_interval_upper_bound: a FLOAT64 value that contains the upper bound of the prediction interval for each forecasted point.
  • confidence_interval_lower_bound: a FLOAT64 value that contains the lower bound of the prediction interval for each forecasted point.
  • confidence_interval_upper_bound: a FLOAT64 value that contains the upper bound of the prediction interval for each forecasted point.

The output of ML.FORECAST has the following properties:

  • For each time series, the output rows are sorted in the chronological order of forecast_timestamp.
  • forecast_timestamp always has a type of TIMESTAMP, regardless of the type of the column specified in the TIME_SERIES_TIMESTAMP_COL option of the CREATE MODEL statement.

ARIMA_PLUS example

The following example forecasts 30 time points with a confidence level of 0.8:

SELECT
  *
FROM
  ML.FORECAST(MODEL `mydataset.mymodel`,
    STRUCT(30 AS horizon, 0.8 AS confidence_level))

ARIMA_PLUS_XREG example

The following example forecasts 30 time points with a confidence level of 0.8 with future features:

SELECT
  *
FROM
  ML.FORECAST(MODEL `mydataset.mymodel`,
    STRUCT(30 AS horizon, 0.8 AS confidence_level),
    (SELECT * FROM `mydataset.mytable`))

Limitation

Applying any additional computation directly on top of ML.FORECAST's result columns might lead to an out-of-memory issue if the model size is too large. Examples are calculating minimum or maximum values, or adding to or subtracting from a particular column. If you are trying to filter on the forecasted value, it's highly recommended to consider the forecast with limit option as an alternative since it implements better algorithms.

What's next