Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
myenv
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
Binary file added Brent_v3.M.xlsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems we are not using this file. it would be best if we remove it.

Binary file not shown.
291 changes: 286 additions & 5 deletions docs/examples/forecaster-quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,296 @@
]
},
{
"cell_type": "markdown",
"id": "6a8ae523",
"cell_type": "code",
"execution_count": 1,
"id": "9d08da3e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" See https://github.com/google-research/timesfm/blob/master/README.md for updated APIs.\n",
"h = 2 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:p-29740:t-25856:modeling_flowstate.py:__init__:Number of encoder parameters: 7885.8240000000005k\n",
"INFO:p-29740:t-25856:modeling_flowstate.py:__init__:Number of dencoder parameters: 1181.952k (14.99%)\n",
"100%|██████████| 1/1 [00:00<00:00, 1.74it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" unique_id ds FlowState\n",
"0 brent 2025-09-14 -10.250992\n",
"1 brent 2025-09-21 -7.985748\n",
" h = 1 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:p-29740:t-25856:modeling_flowstate.py:__init__:Number of encoder parameters: 7885.8240000000005k\n",
"INFO:p-29740:t-25856:modeling_flowstate.py:__init__:Number of dencoder parameters: 1181.952k (14.99%)\n",
"100%|██████████| 1/1 [00:00<00:00, 2.07it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" unique_id ds FlowState\n",
"0 brent 2025-09-14 -10.250992\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"import pandas as pd\n",
"from timecopilot import TimeCopilotForecaster\n",
"from timecopilot.models.foundation.flowstate import FlowState\n",
"\n",
"\n",
"\n",
"df = pd.read_excel(\n",
" # \"https://timecopilot.s3.amazonaws.com/public/data/events_pageviews.csv\",\n",
" 'D:/AO/timecopilot/Brent_v3.M.xlsx',\n",
" parse_dates=[\"ds\"],\n",
")\n",
"\n",
"df_w = (\n",
" df\n",
" .set_index(\"ds\")\n",
" .groupby(\"unique_id\")[\"y\"]\n",
" .resample(\"W\")\n",
" .sum()\n",
" .reset_index()\n",
")\n",
"\n",
"\n",
"\n",
"tcf = TimeCopilotForecaster(\n",
" models=[\n",
" FlowState(), \n",
" ]\n",
")\n",
"\n",
"print(\"h = 2 \")\n",
"fcst_h2 = tcf.forecast(\n",
" df=df_w,\n",
" h=2,\n",
" freq=\"W\",\n",
")\n",
"print(fcst_h2.head())\n",
"\n",
"print(\" h = 1 \")\n",
"fcst_h1 = tcf.forecast(\n",
" df=df_w,\n",
" h=1,\n",
" freq=\"W\",\n",
")\n",
"print(fcst_h1.head())\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "37ba8935",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" unique_id ds y\n",
"0 brent 2005-09-01 63.48\n",
"1 brent 2005-10-01 58.10\n",
"2 brent 2005-11-01 55.05\n",
"3 brent 2005-12-01 58.98\n",
"4 brent 2006-01-01 65.99\n",
".. ... ... ...\n",
"236 brent 2025-05-01 63.90\n",
"237 brent 2025-06-01 67.61\n",
"238 brent 2025-07-01 72.53\n",
"239 brent 2025-08-01 68.12\n",
"240 brent 2025-09-01 66.75\n",
"\n",
"[241 rows x 3 columns]\n",
" unique_id ds y\n",
"0 Oktoberfest 2020-01-31 25376\n",
"1 Oktoberfest 2020-02-29 28470\n",
"2 Oktoberfest 2020-03-31 23816\n",
"3 Oktoberfest 2020-04-30 46186\n",
"4 Oktoberfest 2020-05-31 31213\n",
".. ... ... ...\n",
"403 Thanksgiving 2025-04-30 47655\n",
"404 Thanksgiving 2025-05-31 48667\n",
"405 Thanksgiving 2025-06-30 56856\n",
"406 Thanksgiving 2025-07-31 38935\n",
"407 Thanksgiving 2025-08-31 50620\n",
"\n",
"[408 rows x 3 columns]\n"
]
}
],
"source": [
"import pandas as pd\n",
"df = pd.read_excel('D:/AO/timecopilot/Brent_v3.M.xlsx')\n",
"print(df)\n",
"\n",
"\n",
"import pandas as pd\n",
"df = pd.read_csv('https://timecopilot.s3.amazonaws.com/public/data/events_pageviews.csv')\n",
"print(df)\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "0fb3f02c",
"metadata": {},
"source": []
"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>unique_id</th>\n",
" <th>ds</th>\n",
" <th>y</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Oktoberfest</td>\n",
" <td>2020-01-31</td>\n",
" <td>25376</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Oktoberfest</td>\n",
" <td>2020-02-29</td>\n",
" <td>28470</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Oktoberfest</td>\n",
" <td>2020-03-31</td>\n",
" <td>23816</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Oktoberfest</td>\n",
" <td>2020-04-30</td>\n",
" <td>46186</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Oktoberfest</td>\n",
" <td>2020-05-31</td>\n",
" <td>31213</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>403</th>\n",
" <td>Thanksgiving</td>\n",
" <td>2025-04-30</td>\n",
" <td>47655</td>\n",
" </tr>\n",
" <tr>\n",
" <th>404</th>\n",
" <td>Thanksgiving</td>\n",
" <td>2025-05-31</td>\n",
" <td>48667</td>\n",
" </tr>\n",
" <tr>\n",
" <th>405</th>\n",
" <td>Thanksgiving</td>\n",
" <td>2025-06-30</td>\n",
" <td>56856</td>\n",
" </tr>\n",
" <tr>\n",
" <th>406</th>\n",
" <td>Thanksgiving</td>\n",
" <td>2025-07-31</td>\n",
" <td>38935</td>\n",
" </tr>\n",
" <tr>\n",
" <th>407</th>\n",
" <td>Thanksgiving</td>\n",
" <td>2025-08-31</td>\n",
" <td>50620</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>408 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" unique_id ds y\n",
"0 Oktoberfest 2020-01-31 25376\n",
"1 Oktoberfest 2020-02-29 28470\n",
"2 Oktoberfest 2020-03-31 23816\n",
"3 Oktoberfest 2020-04-30 46186\n",
"4 Oktoberfest 2020-05-31 31213\n",
".. ... ... ...\n",
"403 Thanksgiving 2025-04-30 47655\n",
"404 Thanksgiving 2025-05-31 48667\n",
"405 Thanksgiving 2025-06-30 56856\n",
"406 Thanksgiving 2025-07-31 38935\n",
"407 Thanksgiving 2025-08-31 50620\n",
"\n",
"[408 rows x 3 columns]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "myenv",
"language": "python",
"name": "python3"
},
Expand All @@ -269,7 +550,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.12"
"version": "3.10.11"
}
},
"nbformat": 4,
Expand Down
3 changes: 2 additions & 1 deletion timecopilot/models/foundation/flowstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def _predict_batch(
batch_first=False,
).prediction_outputs
fcst = fcst.squeeze(-1).transpose(-1, -2) # now shape is (batch, h, quantiles)
fcst_mean = fcst[..., supported_quantiles.index(0.5)].squeeze()
# fcst_mean = fcst[..., supported_quantiles.index(0.5)].squeeze()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this commented line.

fcst_mean = fcst[..., supported_quantiles.index(0.5)]
fcst_mean_np = fcst_mean.detach().numpy()
fcst_quantiles_np = fcst.detach().numpy() if quantiles is not None else None
return fcst_mean_np, fcst_quantiles_np
Expand Down
Loading