Open In Colab


How to create a Forecaster#


In Chronos, Forecaster (bigdl.chronos.forecaster.Forecaster) is the forecasting abstraction. It hides the complex logic of model’s creation, training, scaling to cluster, tuning, optimization and inferencing while expose some APIs for users to control.

In this guide, we will use the TCNForecaster and nyc_taxi datasets as examples to describe how to create a Forecaster.

Prepare Environments#

Before creating a forecaster, we need to install Chronos. Chronos supports deep learning backend implemented by pytorch and tensorflow and machine learning methods based on arima and prophet.

[ ]:
# uncomment following 1 lines for pytorch backend
!pip install --pre --upgrade bigdl-chronos[pytorch]

# uncomment following 2 lines for tensorflow backend
# !pip install --pre --upgrade bigdl-chronos
# !pip install --pre --upgrade bigdl-nano[tensorflow]

# installation trick on colab (no need to do these on your own environment)
!pip uninstall torchtext -y

Create a forecaster#

We provide two ways to create a Forecaster.

  • Create by Forecaster.from_tsdataset(Recommended if valid)

  • Create by Forecaster(...) directly

Before creating a Forecaster, We need to know the four parameters past_seq_len, future_seq_len, input_feature_num, output_feature_num, which represent the time step and feature column, As shown below.


  • past_seq_len: Sampled input length, represents the history time step length. (i.e. lookback)

  • future_seq_len: Sampled output length, represents the output time step length.(i.e. horizon)

  • input_feature_num: All feature column(s), including extra feature column(s) and target column(s).

  • output_feature_num: Only target column(s).

More Forecaster info, please refer to Time Series Forecasting OverView

If you want to create a traditional statistic forecaster(e.g. ProphetForecaster or ARIMAForecaster), you may refer to their API doc directly since they are relatively easy and do not have required parameters to create them.

[ ]:
# create a TSDataset
from import get_public_dataset

tsdataset = get_public_dataset('nyc_taxi', with_split=False)


from_tsdataset is a classmethod, so you can call Forecsater.from_tsdataset, then input a TSDataset instance, where TSDataset is a built-in time series preprocessing class.

If the roll or to_torch_data_loader method has been called by tsdataset, past_seq_len and future_seq_len do not need to be specified for from_tsdataset, otherwise both must be specified.

[ ]:
# uncomment following 1 lines for pytorch backend
from bigdl.chronos.forecaster import TCNForecaster

# uncomment following 1 lines for tensorflow backend
# from import TCNForecaster

tcn = TCNForecaster.from_tsdataset(tsdataset,

📝 Note

We recommend to use Forecsater.from_tsdataset if possible. While for some reasons, some forecasters (e.g. ProphetForecaster and ARIMAForecaster) does not support this API. Or maybe you want to process your data customizedly without using TSDataset, you may create a forecaster directly by calling Forecaster(...).

Create a forecaster directly#

You can also create forecaster directly, the parameters mentioned above still need to be specified.

[ ]:
tcn = TCNForecaster(past_seq_len=48,