Skip to content

Commit

Permalink
update_examples
Browse files Browse the repository at this point in the history
  • Loading branch information
elephaint committed Nov 14, 2024
1 parent 6c2d05e commit 7765d49
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 438 deletions.
115 changes: 100 additions & 15 deletions nbs/examples/AustralianDomesticTourism-Bootstraped-Intervals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"os.environ['NIXTLA_ID_AS_COL'] = '1'\n",
"\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
Expand Down Expand Up @@ -70,14 +73,107 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"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>Country</th>\n",
" <th>Region</th>\n",
" <th>State</th>\n",
" <th>Purpose</th>\n",
" <th>ds</th>\n",
" <th>y</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Australia</td>\n",
" <td>Adelaide</td>\n",
" <td>South Australia</td>\n",
" <td>Business</td>\n",
" <td>1998-01-01</td>\n",
" <td>135.077690</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Australia</td>\n",
" <td>Adelaide</td>\n",
" <td>South Australia</td>\n",
" <td>Business</td>\n",
" <td>1998-04-01</td>\n",
" <td>109.987316</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Australia</td>\n",
" <td>Adelaide</td>\n",
" <td>South Australia</td>\n",
" <td>Business</td>\n",
" <td>1998-07-01</td>\n",
" <td>166.034687</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Australia</td>\n",
" <td>Adelaide</td>\n",
" <td>South Australia</td>\n",
" <td>Business</td>\n",
" <td>1998-10-01</td>\n",
" <td>127.160464</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Australia</td>\n",
" <td>Adelaide</td>\n",
" <td>South Australia</td>\n",
" <td>Business</td>\n",
" <td>1999-01-01</td>\n",
" <td>137.448533</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Country Region State Purpose ds y\n",
"0 Australia Adelaide South Australia Business 1998-01-01 135.077690\n",
"1 Australia Adelaide South Australia Business 1998-04-01 109.987316\n",
"2 Australia Adelaide South Australia Business 1998-07-01 166.034687\n",
"3 Australia Adelaide South Australia Business 1998-10-01 127.160464\n",
"4 Australia Adelaide South Australia Business 1999-01-01 137.448533"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Y_df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/tourism.csv')\n",
"Y_df = Y_df.rename({'Trips': 'y', 'Quarter': 'ds'}, axis=1)\n",
"Y_df.insert(0, 'Country', 'Australia')\n",
"Y_df = Y_df[['Country', 'Region', 'State', 'Purpose', 'ds', 'y']]\n",
"Y_df['ds'] = Y_df['ds'].str.replace(r'(\\d+) (Q\\d)', r'\\1-\\2', regex=True)\n",
"Y_df['ds'] = pd.to_datetime(Y_df['ds'])\n",
"Y_df['ds'] = Y_df['ds'].str.replace(r'(\\d+) (Q\\d)', r'\\1\\2', regex=True)\n",
"Y_df['ds'] = pd.PeriodIndex(Y_df[\"ds\"], freq='Q').to_timestamp()\n",
"Y_df.head()"
]
},
Expand Down Expand Up @@ -461,18 +557,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\ospra\\miniconda3\\envs\\hierarchicalforecast-backup\\lib\\site-packages\\statsforecast\\core.py:494: FutureWarning: In a future version the predictions will have the id as a column. You can set the `NIXTLA_ID_AS_COL` environment variable to adopt the new behavior and to suppress this warning.\n",
" warnings.warn(\n",
"c:\\Users\\ospra\\miniconda3\\envs\\hierarchicalforecast-backup\\lib\\site-packages\\statsforecast\\core.py:494: FutureWarning: In a future version the predictions will have the id as a column. You can set the `NIXTLA_ID_AS_COL` environment variable to adopt the new behavior and to suppress this warning.\n",
" warnings.warn(\n"
]
}
],
"outputs": [],
"source": [
"fcst = StatsForecast(models=[AutoETS(season_length=4, model='ZAA')],\n",
" freq='QS', n_jobs=-1)\n",
Expand Down
13 changes: 4 additions & 9 deletions nbs/examples/AustralianDomesticTourism-Intervals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"os.environ['NIXTLA_ID_AS_COL'] = '1'\n",
"\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
Expand Down Expand Up @@ -71,14 +74,6 @@
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\ospra\\AppData\\Local\\Temp\\ipykernel_22304\\195672216.py:6: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
" Y_df['ds'] = pd.to_datetime(Y_df['ds'])\n"
]
},
{
"data": {
"text/html": [
Expand Down Expand Up @@ -178,7 +173,7 @@
"Y_df.insert(0, 'Country', 'Australia')\n",
"Y_df = Y_df[['Country', 'Region', 'State', 'Purpose', 'ds', 'y']]\n",
"Y_df['ds'] = Y_df['ds'].str.replace(r'(\\d+) (Q\\d)', r'\\1-\\2', regex=True)\n",
"Y_df['ds'] = pd.to_datetime(Y_df['ds'])\n",
"Y_df['ds'] = pd.PeriodIndex(Y_df[\"ds\"], freq='Q').to_timestamp()\n",
"Y_df.head()"
]
},
Expand Down
Loading

0 comments on commit 7765d49

Please sign in to comment.