diff --git a/.gitignore b/.gitignore index 58fd37be..71d1c244 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +myenv # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/Brent_v3.M.xlsx b/Brent_v3.M.xlsx new file mode 100644 index 00000000..694dff96 Binary files /dev/null and b/Brent_v3.M.xlsx differ diff --git a/docs/examples/forecaster-quickstart.ipynb b/docs/examples/forecaster-quickstart.ipynb index 6239177a..7bb7053d 100644 --- a/docs/examples/forecaster-quickstart.ipynb +++ b/docs/examples/forecaster-quickstart.ipynb @@ -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": [ + "
| \n", + " | unique_id | \n", + "ds | \n", + "y | \n", + "
|---|---|---|---|
| 0 | \n", + "Oktoberfest | \n", + "2020-01-31 | \n", + "25376 | \n", + "
| 1 | \n", + "Oktoberfest | \n", + "2020-02-29 | \n", + "28470 | \n", + "
| 2 | \n", + "Oktoberfest | \n", + "2020-03-31 | \n", + "23816 | \n", + "
| 3 | \n", + "Oktoberfest | \n", + "2020-04-30 | \n", + "46186 | \n", + "
| 4 | \n", + "Oktoberfest | \n", + "2020-05-31 | \n", + "31213 | \n", + "
| ... | \n", + "... | \n", + "... | \n", + "... | \n", + "
| 403 | \n", + "Thanksgiving | \n", + "2025-04-30 | \n", + "47655 | \n", + "
| 404 | \n", + "Thanksgiving | \n", + "2025-05-31 | \n", + "48667 | \n", + "
| 405 | \n", + "Thanksgiving | \n", + "2025-06-30 | \n", + "56856 | \n", + "
| 406 | \n", + "Thanksgiving | \n", + "2025-07-31 | \n", + "38935 | \n", + "
| 407 | \n", + "Thanksgiving | \n", + "2025-08-31 | \n", + "50620 | \n", + "
408 rows × 3 columns
\n", + "