Created
October 8, 2022 13:35
-
-
Save ngupta23/fe385efcad52b1d6c4c11f955d13da8e to your computer and use it in GitHub Desktop.
sktime_forecasting_pipeline_missing_13p2.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [], | |
"authorship_tag": "ABX9TyPWdToY80IyRY9M0iQj0cAX", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/ngupta23/fe385efcad52b1d6c4c11f955d13da8e/sktime_forecasting_pipeline_missing_13p2.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"id": "dd0XW1sgtCkh" | |
}, | |
"outputs": [], | |
"source": [ | |
"try:\n", | |
" import sktime\n", | |
"except ModuleNotFoundError:\n", | |
" !pip install sktime==0.13.2" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import numpy as np\n", | |
"from sktime.datasets import load_longley\n", | |
"from sktime.forecasting.trend import TrendForecaster\n", | |
"from sktime.transformations.compose import TransformerPipeline\n", | |
"from sktime.forecasting.compose import ForecastingPipeline, TransformedTargetForecaster\n", | |
"from sktime.transformations.series.impute import Imputer" | |
], | |
"metadata": { | |
"id": "2xRDC6ButLBC" | |
}, | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"y, X = load_longley()\n", | |
"y[10] = np.nan" | |
], | |
"metadata": { | |
"id": "PvBHcEBytQHQ" | |
}, | |
"execution_count": 3, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"transformer_y = TransformerPipeline(steps = [(\"imputer\", Imputer())])\n", | |
"\n", | |
"forecaster = TransformedTargetForecaster(\n", | |
" steps = [\n", | |
" (\"transformer_y\", transformer_y),\n", | |
" (\"model\", TrendForecaster())\n", | |
" ]\n", | |
")\n", | |
"\n", | |
"pipe = ForecastingPipeline(steps = [(\"forecaster\", forecaster)])" | |
], | |
"metadata": { | |
"id": "D_E8_F2TtQ1g" | |
}, | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"pipe.fit(y, X)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "CV_wOcRntVQQ", | |
"outputId": "497a2f84-7f3a-48f2-e07e-158212efd017" | |
}, | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stderr", | |
"text": [ | |
"/usr/local/lib/python3.7/dist-packages/sktime/forecasting/trend.py:76: FutureWarning: casting period[A-DEC] values to int64 with .astype(...) is deprecated and will raise in a future version. Use .view(...) instead.\n", | |
" X = y.index.astype(\"int\").to_numpy().reshape(-1, 1)\n" | |
] | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"ForecastingPipeline(steps=[('forecaster',\n", | |
" TransformedTargetForecaster(steps=[('transformer_y',\n", | |
" TransformerPipeline(steps=[('imputer',\n", | |
" Imputer())])),\n", | |
" ('model',\n", | |
" TrendForecaster())]))])" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 5 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment