{ "cells": [ { "cell_type": "markdown", "id": "b5d44943", "metadata": {}, "source": [ "# TSLib for v2 - Example notebook for full pipeline" ] }, { "cell_type": "markdown", "id": "b7d27b55", "metadata": {}, "source": [ "## Basic imports for getting started\n", "\n", "This notebook is a basic vignette for the usage of the `tslib` data module on the `TimeXer` model for the v2 of PyTorch Forecasting. This is an experimental version and is an unstable version of the API.\n", "\n", "Feedback and suggestions on this pipeline - PR [#1836](https://github.com/sktime/pytorch-forecasting/pull/1836)" ] }, { "cell_type": "code", "execution_count": null, "id": "550a3fbf", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "from sklearn.preprocessing import StandardScaler\n", "import torch\n", "\n", "from pytorch_forecasting.data.data_module import TslibDataModule\n", "from pytorch_forecasting.data.encoders import (\n", " NaNLabelEncoder,\n", " TorchNormalizer,\n", ")\n", "from pytorch_forecasting.data.timeseries import TimeSeries\n", "from pytorch_forecasting.models.timexer._timexer_v2 import TimeXer" ] }, { "cell_type": "markdown", "id": "2625ed3d", "metadata": {}, "source": [ "## Construct a time series dataset\n", "\n", "This step requires us to build a `TimeSeries` object for creating a time series dataset, which identifies the features from a raw time series dataset. As you can see below, we are initialising a sample time series dataset." ] }, { "cell_type": "code", "execution_count": 2, "id": "a0058487", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | series_id | \n", "time_idx | \n", "x | \n", "y | \n", "category | \n", "future_known_feature | \n", "static_feature | \n", "static_feature_cat | \n", "
|---|---|---|---|---|---|---|---|---|
| 0 | \n", "0 | \n", "0 | \n", "0.177658 | \n", "0.181124 | \n", "0 | \n", "1.000000 | \n", "0.409581 | \n", "0 | \n", "
| 1 | \n", "0 | \n", "1 | \n", "0.181124 | \n", "0.314081 | \n", "0 | \n", "0.995004 | \n", "0.409581 | \n", "0 | \n", "
| 2 | \n", "0 | \n", "2 | \n", "0.314081 | \n", "0.601934 | \n", "0 | \n", "0.980067 | \n", "0.409581 | \n", "0 | \n", "
| 3 | \n", "0 | \n", "3 | \n", "0.601934 | \n", "0.733805 | \n", "0 | \n", "0.955336 | \n", "0.409581 | \n", "0 | \n", "
| 4 | \n", "0 | \n", "4 | \n", "0.733805 | \n", "0.768843 | \n", "0 | \n", "0.921061 | \n", "0.409581 | \n", "0 | \n", "