{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "671a3715",
   "metadata": {},
   "outputs": [],
   "source": [
    "#| hide\n",
    "!pip install -Uqq nixtla"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83517172",
   "metadata": {},
   "outputs": [],
   "source": [
    "#| hide \n",
    "from nixtla.utils import in_colab"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00464b5b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#| hide \n",
    "IN_COLAB = in_colab()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "991f703b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#| hide\n",
    "if not IN_COLAB:\n",
    "    from nixtla.utils import colab_badge\n",
    "    from dotenv import load_dotenv"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42bb08a4-4ce5-4022-bb65-041c0cdf8890",
   "metadata": {},
   "source": [
    "# Holidays and special dates"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e84c2ca-7dc1-4c48-8dca-5e170a397ed2",
   "metadata": {},
   "source": [
    "Calendar variables and special dates are one of the most common types of additional variables used in forecasting applications. They provide additional context on the current state of the time series, especially for window-based models such as TimeGPT-1. These variables often include adding information on each observation's month, week, day, or hour. For example, in high-frequency hourly data, providing the current month of the year provides more context than the limited history available in the input window to improve the forecasts.\n",
    "\n",
    "In this tutorial we will show how to add calendar variables automatically to a dataset using the `date_features` function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "553a8be7-7664-4dff-a232-e512e5eb26a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "[![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Nixtla/nixtla/blob/main/nbs/docs/tutorials/02_holidays.ipynb)"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#| echo: false\n",
    "if not IN_COLAB:\n",
    "    load_dotenv()    \n",
    "    colab_badge('docs/tutorials/02_holidays')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46efe990",
   "metadata": {},
   "source": [
    "## 1. Import packages\n",
    "First, we import the required packages and initialize the Nixtla client."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd410558-513e-4eb9-ae95-fcca358fa2b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from nixtla import NixtlaClient"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ba19c7b-8222-4114-a1c2-6e9ea52f4a1a",
   "metadata": {},
   "outputs": [],
   "source": [
    "nixtla_client = NixtlaClient(\n",
    "    # defaults to os.environ.get(\"NIXTLA_API_KEY\")\n",
    "    api_key = 'my_api_key_provided_by_nixtla'\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e325b27",
   "metadata": {},
   "source": [
    "> 👍 Use an Azure AI endpoint\n",
    "> \n",
    "> To use an Azure AI endpoint, remember to set also the `base_url` argument:\n",
    "> \n",
    "> `nixtla_client = NixtlaClient(base_url=\"you azure ai endpoint\", api_key=\"your api_key\")`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7c4f11ff-6190-48f9-8cc7-b8c599b0de33",
   "metadata": {},
   "outputs": [],
   "source": [
    "#| hide\n",
    "if not IN_COLAB:\n",
    "    nixtla_client = NixtlaClient()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf43e0a1",
   "metadata": {},
   "source": [
    "## 2. Load data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb3adafb-65e6-44b4-b1e9-0e12b5ff46ed",
   "metadata": {},
   "source": [
    "We will use a Google trends dataset on chocolate, with monthly data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fdcbffe4-add7-4087-86c0-71a584191080",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/google_trend_chocolate.csv')\n",
    "df['month'] = pd.to_datetime(df['month']).dt.to_period('M').dt.to_timestamp('M')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0f8c709b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>chocolate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2004-01-31</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2004-02-29</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2004-03-31</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2004-04-30</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2004-05-31</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       month  chocolate\n",
       "0 2004-01-31         35\n",
       "1 2004-02-29         45\n",
       "2 2004-03-31         28\n",
       "3 2004-04-30         30\n",
       "4 2004-05-31         29"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "870d9cd5",
   "metadata": {},
   "source": [
    "## 3. Forecasting with holidays and special dates"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7cbcded8",
   "metadata": {},
   "source": [
    "Given the predominance usage of calendar variables, we included an automatic creation of common calendar variables to the forecast method as a pre-processing step. Let's create a future dataframe that contains the upcoming holidays in the United States."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "341da194",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create future dataframe with exogenous features\n",
    "\n",
    "start_date = '2024-05'\n",
    "dates = pd.date_range(start=start_date, periods=14, freq='M')\n",
    "\n",
    "dates = dates.to_period('M').to_timestamp('M')\n",
    "\n",
    "future_df = pd.DataFrame(dates, columns=['month'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f0af006e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>US_New Year's Day</th>\n",
       "      <th>US_Memorial Day</th>\n",
       "      <th>US_Juneteenth National Independence Day</th>\n",
       "      <th>US_Independence Day</th>\n",
       "      <th>US_Labor Day</th>\n",
       "      <th>US_Veterans Day</th>\n",
       "      <th>US_Thanksgiving</th>\n",
       "      <th>US_Christmas Day</th>\n",
       "      <th>US_Martin Luther King Jr. Day</th>\n",
       "      <th>US_Washington's Birthday</th>\n",
       "      <th>US_Columbus Day</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2024-05-31</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2024-06-30</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2024-07-31</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2024-08-31</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2024-09-30</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       month  US_New Year's Day  US_Memorial Day  \\\n",
       "0 2024-05-31                  0                0   \n",
       "1 2024-06-30                  0                0   \n",
       "2 2024-07-31                  0                0   \n",
       "3 2024-08-31                  0                0   \n",
       "4 2024-09-30                  0                0   \n",
       "\n",
       "   US_Juneteenth National Independence Day  US_Independence Day  US_Labor Day  \\\n",
       "0                                        0                    0             0   \n",
       "1                                        1                    0             0   \n",
       "2                                        0                    1             0   \n",
       "3                                        0                    0             0   \n",
       "4                                        0                    0             1   \n",
       "\n",
       "   US_Veterans Day  US_Thanksgiving  US_Christmas Day  \\\n",
       "0                0                0                 0   \n",
       "1                0                0                 0   \n",
       "2                0                0                 0   \n",
       "3                0                0                 0   \n",
       "4                0                0                 0   \n",
       "\n",
       "   US_Martin Luther King Jr. Day  US_Washington's Birthday  US_Columbus Day  \n",
       "0                              0                         0                0  \n",
       "1                              0                         0                0  \n",
       "2                              0                         0                0  \n",
       "3                              0                         0                0  \n",
       "4                              0                         0                0  "
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from nixtla.date_features import CountryHolidays\n",
    "\n",
    "us_holidays = CountryHolidays(countries=['US'])\n",
    "dates = pd.date_range(start=future_df.iloc[0]['month'], end=future_df.iloc[-1]['month'], freq='D')\n",
    "holidays_df = us_holidays(dates)\n",
    "monthly_holidays = holidays_df.resample('M').max()\n",
    "\n",
    "monthly_holidays = monthly_holidays.reset_index(names='month')\n",
    "\n",
    "future_df = future_df.merge(monthly_holidays)\n",
    "\n",
    "future_df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f32286cb",
   "metadata": {},
   "source": [
    "We perform the same steps for the input dataframe."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a8a2514",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>chocolate</th>\n",
       "      <th>US_New Year's Day</th>\n",
       "      <th>US_New Year's Day (observed)</th>\n",
       "      <th>US_Memorial Day</th>\n",
       "      <th>US_Independence Day</th>\n",
       "      <th>US_Independence Day (observed)</th>\n",
       "      <th>US_Labor Day</th>\n",
       "      <th>US_Veterans Day</th>\n",
       "      <th>US_Thanksgiving</th>\n",
       "      <th>US_Christmas Day</th>\n",
       "      <th>US_Christmas Day (observed)</th>\n",
       "      <th>US_Martin Luther King Jr. Day</th>\n",
       "      <th>US_Washington's Birthday</th>\n",
       "      <th>US_Columbus Day</th>\n",
       "      <th>US_Veterans Day (observed)</th>\n",
       "      <th>US_Juneteenth National Independence Day</th>\n",
       "      <th>US_Juneteenth National Independence Day (observed)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>90</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>2024-01-31</td>\n",
       "      <td>64</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>241</th>\n",
       "      <td>2024-02-29</td>\n",
       "      <td>66</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>242</th>\n",
       "      <td>2024-03-31</td>\n",
       "      <td>59</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>243</th>\n",
       "      <td>2024-04-30</td>\n",
       "      <td>51</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         month  chocolate  US_New Year's Day  US_New Year's Day (observed)  \\\n",
       "239 2023-12-31         90                  0                             0   \n",
       "240 2024-01-31         64                  1                             0   \n",
       "241 2024-02-29         66                  0                             0   \n",
       "242 2024-03-31         59                  0                             0   \n",
       "243 2024-04-30         51                  0                             0   \n",
       "\n",
       "     US_Memorial Day  US_Independence Day  US_Independence Day (observed)  \\\n",
       "239                0                    0                               0   \n",
       "240                0                    0                               0   \n",
       "241                0                    0                               0   \n",
       "242                0                    0                               0   \n",
       "243                0                    0                               0   \n",
       "\n",
       "     US_Labor Day  US_Veterans Day  US_Thanksgiving  US_Christmas Day  \\\n",
       "239             0                0                0                 1   \n",
       "240             0                0                0                 0   \n",
       "241             0                0                0                 0   \n",
       "242             0                0                0                 0   \n",
       "243             0                0                0                 0   \n",
       "\n",
       "     US_Christmas Day (observed)  US_Martin Luther King Jr. Day  \\\n",
       "239                            0                              0   \n",
       "240                            0                              1   \n",
       "241                            0                              0   \n",
       "242                            0                              0   \n",
       "243                            0                              0   \n",
       "\n",
       "     US_Washington's Birthday  US_Columbus Day  US_Veterans Day (observed)  \\\n",
       "239                         0                0                           0   \n",
       "240                         0                0                           0   \n",
       "241                         1                0                           0   \n",
       "242                         0                0                           0   \n",
       "243                         0                0                           0   \n",
       "\n",
       "     US_Juneteenth National Independence Day  \\\n",
       "239                                        0   \n",
       "240                                        0   \n",
       "241                                        0   \n",
       "242                                        0   \n",
       "243                                        0   \n",
       "\n",
       "     US_Juneteenth National Independence Day (observed)  \n",
       "239                                                  0   \n",
       "240                                                  0   \n",
       "241                                                  0   \n",
       "242                                                  0   \n",
       "243                                                  0   "
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Add exogenous features to input dataframe\n",
    "\n",
    "dates = pd.date_range(start=df.iloc[0]['month'], end=df.iloc[-1]['month'], freq='D')\n",
    "holidays_df = us_holidays(dates)\n",
    "monthly_holidays = holidays_df.resample('M').max()\n",
    "\n",
    "monthly_holidays = monthly_holidays.reset_index(names='month')\n",
    "\n",
    "df = df.merge(monthly_holidays)\n",
    "\n",
    "df.tail()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bcc34ab7",
   "metadata": {},
   "source": [
    "Great! Now, TimeGPT will consider the holidays as exogenous variables and the upcoming holidays will help it make predictions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3372c3dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:nixtla.nixtla_client:Validating inputs...\n",
      "INFO:nixtla.nixtla_client:Preprocessing dataframes...\n",
      "INFO:nixtla.nixtla_client:Inferred freq: M\n",
      "WARNING:nixtla.nixtla_client:The specified horizon \"h\" exceeds the model horizon. This may lead to less accurate forecasts. Please consider using a smaller horizon.\n",
      "INFO:nixtla.nixtla_client:Using the following exogenous variables: US_New Year's Day, US_Memorial Day, US_Juneteenth National Independence Day, US_Independence Day, US_Labor Day, US_Veterans Day, US_Thanksgiving, US_Christmas Day, US_Martin Luther King Jr. Day, US_Washington's Birthday, US_Columbus Day\n",
      "INFO:nixtla.nixtla_client:Calling Forecast Endpoint...\n"
     ]
    }
   ],
   "source": [
    "fcst_df = nixtla_client.forecast(\n",
    "    df=df,\n",
    "    h=14,\n",
    "    freq='M',\n",
    "    time_col='month',\n",
    "    target_col='chocolate',\n",
    "    X_df=future_df\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31de98bf",
   "metadata": {},
   "source": [
    "> 📘 Available models in Azure AI\n",
    ">\n",
    "> If you are using an Azure AI endpoint, please be sure to set `model=\"azureai\"`:\n",
    ">\n",
    "> `nixtla_client.forecast(..., model=\"azureai\")`\n",
    "> \n",
    "> For the public API, we support two models: `timegpt-1` and `timegpt-1-long-horizon`. \n",
    "> \n",
    "> By default, `timegpt-1` is used. Please see [this tutorial](https://docs.nixtla.io/docs/tutorials-long_horizon_forecasting) on how and when to use `timegpt-1-long-horizon`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48a845e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 127016 characters]",
      "text/plain": [
       "<Figure size 2400x350 with 1 Axes>"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nixtla_client.plot(\n",
    "    df, \n",
    "    fcst_df, \n",
    "    time_col='month',\n",
    "    target_col='chocolate',\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b75b4388",
   "metadata": {},
   "source": [
    "We can then plot the weights of each holiday to see which are more important in forecasing the interest in chocolate."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "746e3143",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: ylabel='features'>"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 55216 characters]",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "nixtla_client.weights_x.plot.barh(x='features', y='weights', figsize=(10, 10))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0c17ee3-e9a1-45de-b2e1-2b8b0094bb31",
   "metadata": {},
   "source": [
    "\n",
    "Here's a breakdown of how the `date_features` parameter works:\n",
    "\n",
    "- **`date_features` (bool or list of str or callable)**: This parameter specifies which date attributes to consider.\n",
    "    - If set to `True`, the model will automatically add the most common date features related to the frequency of the given dataframe (`df`). For a daily frequency, this could include features like day of the week, month, and year.\n",
    "    - If provided a list of strings, it will consider those specific date attributes. For example, `date_features=['weekday', 'month']` will only add the day of the week and month as features.\n",
    "    - If provided a callable, it should be a function that takes dates as input and returns the desired feature. This gives flexibility in computing custom date features.\n",
    "\n",
    "- **`date_features_to_one_hot` (bool or list of str)**: After determining the date features, one might want to one-hot encode them, especially if they are categorical in nature (like weekdays). One-hot encoding transforms these categorical features into a binary matrix, making them more suitable for many machine learning algorithms.\n",
    "    - If `date_features=True`, then by default, all computed date features will be one-hot encoded.\n",
    "    - If provided a list of strings, only those specific date features will be one-hot encoded.\n",
    "\n",
    "By leveraging the `date_features` and `date_features_to_one_hot` parameters, one can efficiently incorporate the temporal effects of date attributes into their forecasting model, potentially enhancing its accuracy and interpretability."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "python3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
