Stay organized with collectionsSave and categorize content based on your preferences.
Limit forecasted values for an ARIMA_PLUS time series model
This tutorial teaches you how to use limits to narrow the forecasted results returned by anARIMA_PLUStime series model. In this tutorial, you create two time series models over the same data, one model which uses limits and one model that doesn't use limits. This lets you compare the results returned by the models
and understand the difference that specifying limits makes.
You use thenew_york.citibike_tripsdata to train the models in this tutorial. This dataset contains information about Citi Bike trips in New York City.
Sign in to your Google Cloud account. If you're new to
Google Cloud,create an accountto evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator role
(roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant
roles.
To enable APIs, you need the Service Usage Admin IAM
role (roles/serviceusage.serviceUsageAdmin), which
contains theserviceusage.services.enablepermission.Learn how to grant
roles.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator role
(roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant
roles.
To enable APIs, you need the Service Usage Admin IAM
role (roles/serviceusage.serviceUsageAdmin), which
contains theserviceusage.services.enablepermission.Learn how to grant
roles.
Before creating the model, it is useful to see what your input time series
looks like.
SQL
In the following query, theFROM bigquery-public-data.new_york.citibike_tripsclause indicates that you are querying thecitibike_tripstable in thenew_yorkdataset.
In theSELECTstatement, the query uses theEXTRACTfunctionto extract the date information from thestarttimecolumn. The query uses
theCOUNT(*)clause to get the daily total number of Citi Bike trips.
ClickRun. The query results similar to the following.
Use the Google Cloud console to chart the time series data. In theQuery resultspane, click theVisualizationtab. In theVisualization configurationpane, chooseBarfor theVisualization type:
Create a time series model, using the NYC Citi Bike trips data.
The following GoogleSQL query creates a model that forecasts daily total
bike trips. TheCREATE MODELstatement creates and trains a model namedbqml_tutorial.nyc_citibike_arima_model.
TheOPTIONS(model_type='ARIMA_PLUS', time_series_timestamp_col='date', ...)clause indicates that you are creating anARIMA-based
time series model. By default,auto_arima=TRUE,
so theauto.ARIMAalgorithm automatically tunes the hyperparameters inARIMA_PLUSmodels. The algorithm fits dozens of candidate models and chooses
the best one with the lowestAkaike information criterion (AIC).
Additionally, because the default isdata_frequency='AUTO_FREQUENCY', the training process automatically infers
the data frequency of the input time series. TheCREATE MODELstatement usesdecompose_time_series=TRUEby default, so both the history and forecast parts of the time series are saved in the model. Setting the parametertime_series_id_col = 'start_station_id'causes the model to fit and forecast multiple time series using a single query based on thestart_station_id. You can use this information to further understand how the time series is forecasted
by fetching the separate time series components such as seasonal periods.
Run theCREATE MODELquery to create and train your model:
In the Google Cloud console, click theCompose new querybutton.
Enter the following GoogleSQL query in the query editor.
The query takes approximately 80 seconds to complete, after which you can
access the (nyc_citibike_arima_model) model. Because the query uses aCREATE MODELstatement to create a model, there are no query results.
Forecast the time series and visualize the results
To explain how the time series is forecasted, visualize all the sub-time series
components, such as seasonality and trend, using theML.FORECASTfunction.
To do this, follow these steps:
In the Google Cloud console, click theCompose new querybutton.
Enter the following GoogleSQL query in the query editor.
ClickRun. The query results similar to the following:
Use the Google Cloud console to chart the time series data. In theQuery resultspane, click theVisualizationtab:
The chart shows that the forecasted values for the daily total number of Citi
Bike trips wherestart_station_id=79are negative numbers, which isn't useful. Using a model with limits instead improves the forecasted data.
Create a time series model with limits
Create a time series model with limits, using the NYC Citi Bike trips data.
The following GoogleSQL query creates a model that forecasts daily total
bike trips. TheCREATE MODELstatement creates and trains a model namedbqml_tutorial.nyc_citibike_arima_model_with_limits.
The key difference between this model and themodel you created previouslyis the addition of theforecast_limit_lower_bound=0option. This option causes the model to only forecast values that are greater than 0, based on the values in the column specified by thetime_series_data_colargument, in this casenum_trips.
The query takes approximately 100 seconds to complete, after which you can
access the (nyc_citibike_arima_model_with_limits) model. Because the query
uses aCREATE MODELstatement to create a model, there are no query results.
Forecast the time series by using the model with limits
In the Google Cloud console, click theCompose new querybutton.
Enter the following GoogleSQL query in the query editor.
Use the Google Cloud console to chart the time series data. In theQuery resultspane, click theVisualizationtab:
The ARIMA PLUS model detects that the daily total number of Citi Bike trips wherestart_station_id=79is decreasing. Future forecasting values will follow this trend and give relatively smaller forecasting numbers the farther into the future you go. The chart shows that the forecasted values for the daily total number of Citi
Bike trips wherestart_station_id=79are positive numbers, which is more useful. The model with limits
detects that the daily total number of Citi Bike trips wherestart_station_id=79is decreasing, but it still gives meaningful forecasting values.
As this tutorial shows, theforecast_limit_lower_boundandforecast_limit_upper_boundoptions can help you get more meaningful forecasting values in similar scenarios to the one shown here, such as when forecasting stock prices or future sales numbers.
Delete your dataset
Deleting your project removes all datasets and all tables in the project. If you
prefer to reuse the project, you can delete the dataset you created in this
tutorial:
If necessary, open the BigQuery page in the
Google Cloud console.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-03-19 UTC."],[],[]]