* how to guide from_tsdataset * improve md * remove redundant message * fix known issues * add rst * move create-forecaster to new line * fix known issue * fix syntax error * fix syntax error again * add open-colab icon * fix known issues * fix some words * fix typo * fix syntax error * add some update Co-authored-by: theaperdeng <theaperdeng@outlook.com>
206 lines
12 KiB
Text
206 lines
12 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"[](https://colab.research.google.com/github/intel-analytics/BigDL/blob/main/docs/readthedocs/source/doc/Chronos/Howto/how-to-create-forecaster.ipynb)\n",
|
|
"\n",
|
|
"<style>\n",
|
|
" .rst-content blockquote {\n",
|
|
" margin-left: 0px;\n",
|
|
" }\n",
|
|
" \n",
|
|
" blockquote > div {\n",
|
|
" margin: 1.5625em auto;\n",
|
|
" padding: 20px 15px 1px;\n",
|
|
" border-left: 0.2rem solid rgb(59, 136, 219); \n",
|
|
" border-radius: 0.2rem;\n",
|
|
" box-shadow: 0 0.2rem 0.5rem rgb(0 0 0 / 5%), 0 0 0.0625rem rgb(0 0 0 / 10%);\n",
|
|
" }\n",
|
|
"</style>\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# How to create a Forecaster"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Introduction\n",
|
|
"\n",
|
|
"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.\n",
|
|
"\n",
|
|
"In this guide, we will use the `TCNForecaster` and nyc_taxi datasets as examples to describe **how to create a Forecaster**."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Prepare Environments"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"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."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# uncomment following 1 lines for pytorch backend\n",
|
|
"!pip install --pre --upgrade bigdl-chronos[pytorch]\n",
|
|
"\n",
|
|
"# uncomment following 2 lines for tensorflow backend\n",
|
|
"# !pip install --pre --upgrade bigdl-chronos\n",
|
|
"# !pip install --pre --upgrade bigdl-nano[tensorflow]\n",
|
|
"\n",
|
|
"# installation trick on colab (no need to do these on your own environment)\n",
|
|
"!pip uninstall torchtext -y\n",
|
|
"exit()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Create a forecaster\n",
|
|
"We provide two ways to create a Forecaster.\n",
|
|
"\n",
|
|
"* Create by `Forecaster.from_tsdataset`(**Recommended if valid**)\n",
|
|
"* Create by `Forecaster(...)` directly"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"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.\n",
|
|
"\n",
|
|
"<img src=\"../Image/forecast-RR.png\" title=\"time series\" style=\"width:600px\">\n",
|
|
"\n",
|
|
"* **past_seq_len**: Sampled input length, represents the history time step length. (i.e. lookback)\n",
|
|
"* **future_seq_len**: Sampled output length, represents the output time step length.(i.e. horizon)\n",
|
|
"* **input_feature_num**: All feature column(s), including extra feature column(s) and target column(s).\n",
|
|
"* **output_feature_num**: Only target column(s).\n",
|
|
"\n",
|
|
"More Forecaster info, please refer to [Time Series Forecasting OverView](https://bigdl.readthedocs.io/en/latest/doc/Chronos/Overview/forecasting.html#time-series-forecasting-overview)\n",
|
|
"\n",
|
|
"If you want to create a traditional statistic forecaster(e.g. [ProphetForecaster](https://bigdl.readthedocs.io/en/latest/doc/PythonAPI/Chronos/forecasters.html#prophetforecaster) or [ARIMAForecaster](https://bigdl.readthedocs.io/en/latest/doc/PythonAPI/Chronos/forecasters.html#arimaforecaster)), you may refer to their API doc directly since they are relatively easy and do not have required parameters to create them."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# create a TSDataset\n",
|
|
"from bigdl.chronos.data.repo_dataset import get_public_dataset\n",
|
|
"\n",
|
|
"tsdataset = get_public_dataset('nyc_taxi', with_split=False)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Forecaster.from_tsdataset\n",
|
|
"\n",
|
|
"`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.\n",
|
|
"\n",
|
|
"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."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# uncomment following 1 lines for pytorch backend\n",
|
|
"from bigdl.chronos.forecaster import TCNForecaster\n",
|
|
"\n",
|
|
"# uncomment following 1 lines for tensorflow backend\n",
|
|
"# from bigdl.chronos.forecaster.tf import TCNForecaster\n",
|
|
"\n",
|
|
"tcn = TCNForecaster.from_tsdataset(tsdataset,\n",
|
|
" past_seq_len=48,\n",
|
|
" future_seq_len=5)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"> 📝 **Note**\n",
|
|
">\n",
|
|
"> 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(...)`."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Create a forecaster directly\n",
|
|
"You can also create forecaster directly, the parameters mentioned above still need to be specified."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"tcn = TCNForecaster(past_seq_len=48,\n",
|
|
" future_seq_len=5,\n",
|
|
" input_feature_num=2,\n",
|
|
" output_feature_num=2)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3.7.13 ('chronos-deps')",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.7.13"
|
|
},
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "1a7f5d41b94c9ba67b8a1438ec071a63464312bab4ac0991ee31faebf1c9c228"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|