{ "cells": [ { "cell_type": "markdown", "id": "c5046cdf", "metadata": {}, "source": [ "# Inference: using saved pipeline on a new data\n", "\n", "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/etna-team/etna/master?filepath=examples/302-inference.ipynb)" ] }, { "cell_type": "markdown", "id": "b74c7dff", "metadata": {}, "source": [ "This notebook contains the example of usage already fitted and saved pipeline on a new data.\n", "\n", "**Table of contents**\n", "\n", "* [Preparing data](#chapter1)\n", "* [Fitting and saving pipeline](#chapter2)\n", " * [Fitting pipeline](#section_2_1)\n", " * [Saving pipeline](#section_2_2)\n", " * [Method to_dict](#section_2_3)\n", "* [Using saved pipeline on a new data](#chapter3)\n", " * [Loading pipeline](#section_3_1)\n", " * [Forecast on a new data](#section_3_2)" ] }, { "cell_type": "code", "execution_count": 1, "id": "c1053781", "metadata": {}, "outputs": [], "source": [ "import warnings\n", "\n", "warnings.filterwarnings(action=\"ignore\", message=\"Torchmetrics v0.9\")" ] }, { "cell_type": "code", "execution_count": 2, "id": "fc24b98c", "metadata": {}, "outputs": [], "source": [ "import pathlib\n", "\n", "import pandas as pd\n", "\n", "from etna.analysis import plot_forecast\n", "from etna.datasets import TSDataset\n", "from etna.metrics import SMAPE\n", "from etna.models import CatBoostMultiSegmentModel\n", "from etna.pipeline import Pipeline\n", "from etna.transforms import DateFlagsTransform\n", "from etna.transforms import LagTransform\n", "from etna.transforms import LogTransform\n", "from etna.transforms import SegmentEncoderTransform" ] }, { "cell_type": "code", "execution_count": 3, "id": "cb2c820f", "metadata": {}, "outputs": [], "source": [ "HORIZON = 30\n", "SAVE_DIR = pathlib.Path(\"tmp\")\n", "SAVE_DIR.mkdir(exist_ok=True)" ] }, { "cell_type": "markdown", "id": "81e670c8", "metadata": {}, "source": [ "## 1. Preparing data " ] }, { "cell_type": "markdown", "id": "ed4a8e77", "metadata": {}, "source": [ "Let's load data and prepare it for our pipeline." ] }, { "cell_type": "code", "execution_count": 4, "id": "9e8659fc", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | timestamp | \n", "segment | \n", "target | \n", "
---|---|---|---|
0 | \n", "2019-01-01 | \n", "segment_a | \n", "170 | \n", "
1 | \n", "2019-01-02 | \n", "segment_a | \n", "243 | \n", "
2 | \n", "2019-01-03 | \n", "segment_a | \n", "267 | \n", "
3 | \n", "2019-01-04 | \n", "segment_a | \n", "287 | \n", "
4 | \n", "2019-01-05 | \n", "segment_a | \n", "279 | \n", "