Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC] added post-processing notes in tutorial #3878

Merged
71 changes: 39 additions & 32 deletions .all-contributorsrc
Expand Up @@ -1652,7 +1652,6 @@
]
},
{

"login": "AurumnPegasus",
"name": "Shivansh Subramanian",
"avatar_url": "https://avatars.githubusercontent.com/u/54315149?v=4",
Expand Down Expand Up @@ -1702,7 +1701,6 @@
"profile": "https://github.com/mariamjabara",
"contributions": [
"code"

]
},
{
Expand Down Expand Up @@ -1780,7 +1778,7 @@
]
},
{
"login": "bugslayer-332" ,
"login": "bugslayer-332",
"name": "Arepalli Yashwanth Reddy",
"profile": "https://github.com/bugslayer-332",
"contributions": [
Expand Down Expand Up @@ -1845,7 +1843,7 @@
"code",
"test",
"ideas"
]
]
},
{
"login": "KishManani",
Expand All @@ -1858,31 +1856,40 @@
"test",
"bug",
"ideas"
},
{
"login": "jorenham",
"name": "Joren Hammudoglu",
"profile": "https://github.com/jorenham",
"contributions": [
"build"
]
},
{
"login": "wolph",
"name": "Rick van Hattem",
"profile": "https://github.com/wolph",
"contributions": [
"build"
]
},
{
"login": "templierw",
"name": "William Templier",
"avatar_url": "https://github.com/templierw.png",
"profile": "https://www.linkedin.com/in/templierw/",
"contributions": [
"doc"
]
}
]
}
},
{
"login": "jorenham",
"name": "Joren Hammudoglu",
"profile": "https://github.com/jorenham",
"contributions": [
"build"
]
},
{
"login": "wolph",
"name": "Rick van Hattem",
"profile": "https://github.com/wolph",
"contributions": [
"build"
]
},
{
"login": "templierw",
"name": "William Templier",
"avatar_url": "https://github.com/templierw.png",
"profile": "https://www.linkedin.com/in/templierw/",
"contributions": [
"doc"
]
},
{
"login": "nshahpazov",
"name": "Nikola Shahpazov",
"avatar_url": "https://avatars.githubusercontent.com/nshahpazov",
"profile": "https://www.linkedin.com/in/nshahpazov/",
"contributions": [
"doc"
]
}
]
}
81 changes: 77 additions & 4 deletions examples/01_forecasting.ipynb
Expand Up @@ -5365,7 +5365,8 @@
"source": [
"#### 3.2.1 The basic forecasting pipeline<a class=\"anchor\" id=\"section_3_2_1\"></a>\n",
"\n",
"`sktime` provides a generic pipeline object for this kind of composite modelling, the `TransforemdTargetForecaster`. It chains an arbitrary number of transformations with a forecaster. The transformations should be instances of estimators with series-to-series-transformer scitype. An example of the syntax is below:"
"`sktime` provides a generic pipeline object for this kind of composite modelling, the `TransforemdTargetForecaster`. It chains an arbitrary number of transformations with a forecaster. The transformations can either be pre-processing transformations or a post-processing transformations. An example of a forecaster with pre-processing\n",
"transformations can be seen below."
]
},
{
Expand Down Expand Up @@ -5425,7 +5426,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The `TransformedTargetForecaster` is constructed with a list of steps, each a pair of name and estimator. The last estimator should be of forecaster scitype, the other estimators should be series-to-series transformers which possess both a `transform` and `inverse_transform` method. The resulting estimator is of forecaster scitype and has all interface defining methods. In `fit`, all transformers apply `fit_transforms` to the data, then the forecaster's `fit`; in `predict`, first the forecaster's `predict` is applied, then the transformers' `inverse_transform` in reverse order."
"In the above example, the `TransformedTargetForecaster` is constructed with a list of steps, each a pair of name and estimator, where the last estimator is a forecaster scitype. The pre-processing transformers should be series-to-series transformers which possess both a `transform` and an `inverse_transform` method. The resulting estimator is of forecaster scitype and has all interface defining methods. In `fit`, all transformers apply `fit_transforms` to the data, then the forecaster's `fit`; in `predict`, first the forecaster's `predict` is applied, then the transformers' `inverse_transform` in reverse order."
nshahpazov marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
Expand Down Expand Up @@ -5471,7 +5472,7 @@
},
{
"cell_type": "code",
"execution_count": 252,
"execution_count": 182,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -5508,7 +5509,7 @@
" 'ARIMA__with_intercept': True}"
]
},
"execution_count": 252,
"execution_count": 182,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -5523,6 +5524,78 @@
"forecaster.get_params()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also create a pipeline with post-processing transformations, these are transformations *after* the forecaster, in a dunder pipeline or a `TransformedTargetForecaster`.\n",
"\n",
"Below is an example of a multiple seasonality model, with integer rounding post-processing of the predictions:"
]
},
{
"cell_type": "code",
"execution_count": 186,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1958-01 334.0\n",
"1958-02 338.0\n",
"1958-03 317.0\n",
"Freq: M, dtype: float64"
]
},
"execution_count": 186,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sktime.transformations.series.func_transform import FunctionTransformer\n",
"\n",
"forecaster = ARIMA() * FunctionTransformer(lambda y: y.round())\n",
"forecaster.fit_predict(y, fh=fh).head(3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Both pre- and post-processing transformers can be present, in this case the post-processing transformations will be applied after the `inverse-transform` of the pre-processing ones."
]
},
{
"cell_type": "code",
"execution_count": 188,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1958-01 339.0\n",
"1958-02 334.0\n",
"1958-03 381.0\n",
"Freq: M, dtype: float64"
]
},
"execution_count": 188,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"forecaster = (\n",
" Deseasonalizer(model=\"multiplicative\", sp=12)\n",
" * Deseasonalizer(model=\"multiplicative\", sp=3)\n",
" * ARIMA()\n",
" * FunctionTransformer(lambda y: y.round())\n",
")\n",
"\n",
"forecaster.fit_predict(y_train, fh=fh).head(3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down