{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Damped Local Trend (DLT)\n", "\n", "This section covers topics including:\n", "\n", "- DLT model structure\n", "- DLT global trend configurations\n", "- Adding regressors in DLT\n", "- Other configurations" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2022-04-28T21:51:58.563947Z", "start_time": "2022-04-28T21:51:56.242159Z" } }, "outputs": [], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "\n", "import orbit\n", "from orbit.models import DLT\n", "from orbit.diagnostics.plot import plot_predicted_data, plot_predicted_components\n", "from orbit.utils.dataset import load_iclaims" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2022-04-28T21:51:58.568614Z", "start_time": "2022-04-28T21:51:58.565771Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1.1.4.6\n" ] } ], "source": [ "print(orbit.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Model Structure\n", "\n", "**DLT** is one of the main exponential smoothing models we support in `orbit`. Performance is benchmarked with M3 monthly, M4 weekly dataset and some Uber internal dataset [(Ng and Wang et al., 2020)](https://arxiv.org/abs/2004.08492). The model is a fusion between the classical ETS [(Hyndman et. al., 2008)](http://www.exponentialsmoothing.net/home)) with some refinement leveraging ideas from Rlgt [(Smyl et al., 2019)](https://cran.r-project.org/web/packages/Rlgt/index.html). The model has a structural forecast equations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$\n", "\\begin{align*}\n", "y_t &=\\mu_t + s_t + r_t + \\epsilon_t \\\\\n", "\\mu_t &=g_t + l_{t-1} + \\theta{b_{t-1}} \\\\\n", "\\epsilon_t &~\\sim \\mathtt{Student}(\\nu, 0, \\sigma)\\\\\n", "\\sigma &~\\sim \\mathtt{HalfCauchy}(0, \\gamma_0)\n", "\\end{align*}\n", "$$\n", "\n", "with the update process\n", "\n", "$$\n", "\\begin{align*}\n", "g_t &= D(t)\\\\\n", "l_t &= \\rho_l(y_t - g_{t} - s_t - r_t) + (1-\\rho_l)(l_{t-1} + \\theta b_{t-1})\\\\\n", "b_t &= \\rho_b(l_t - l_{t-1}) + (1-\\rho_b)\\theta b_{t-1}\\\\\n", "s_{t+m} &= \\rho_s(y_t - l_t - r_t) + (1-\\rho_s)s_t\\\\\n", "r_t &= \\Sigma_{j}\\beta_j x_{jt}\n", "\\end{align*}\n", "$$\n", "\n", "One important point is that using $y_t$ as a log-transformed response usually yield better result, especially we can interpret such log-transformed model as a *multiplicative form* of the original model. Besides, there are two new additional components compared to the classical damped ETS model:\n", "\n", "1. $D(t)$ as the deterministic trend process\n", "2. $r$ as the regression component with $x$ as the regressors" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2022-03-30T23:45:50.399142Z", "start_time": "2022-03-30T23:45:50.239137Z" } }, "outputs": [], "source": [ "# load log-transformed data\n", "df = load_iclaims()\n", "response_col = 'claims'\n", "date_col = 'week'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
| \n", " | regressor | \n", "regressor_sign | \n", "coefficient | \n", "coefficient_lower | \n", "coefficient_upper | \n", "Pr(coef >= 0) | \n", "Pr(coef < 0) | \n", "
|---|---|---|---|---|---|---|---|
| 0 | \n", "trend.unemploy | \n", "Regular | \n", "0.052448 | \n", "0.020843 | \n", "0.076498 | \n", "1.00 | \n", "0.00 | \n", "
| 1 | \n", "trend.filling | \n", "Regular | \n", "0.084483 | \n", "0.012782 | \n", "0.139546 | \n", "0.99 | \n", "0.01 | \n", "