Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement model cu 86c1f7e46 #256

Closed
Closed
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
247 changes: 247 additions & 0 deletions notebooks/plot_quantile_forecast.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import webdataset as wds\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"patient_names = [\"pat_96002\"]\n",
"file_paths = [f\"/innovation_cache/merged_eeg/{patient_name}.univariate.tar\" for patient_name in patient_names]\n",
"ds = wds.WebDataset(file_paths, shardshuffle=False).decode(\"l\")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"sample = next(ds.iterator())"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'__key__': '0',\n",
" '__url__': '/innovation_cache/merged_eeg/pat_96002.univariate.tar',\n",
" 'index.npy': array(10428150),\n",
" '__local_path__': '/innovation_cache/merged_eeg/pat_96002.univariate.tar',\n",
" 'label.npy': array(0, dtype=int32),\n",
" 'segment.npy': array([ 17.05792731, 28.37108812, 23.97548263, ..., -20.88427017,\n",
" -20.0133777 , 1.76995768])}"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sample"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'autogluon'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[25], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mautogluon\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtimeseries\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m TimeSeriesDataFrame, TimeSeriesPredictor\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'autogluon'"
]
}
],
"source": [
"from autogluon.timeseries import TimeSeriesDataFrame, TimeSeriesPredictor"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'TimeSeriesDataFrame' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[26], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m data \u001b[38;5;241m=\u001b[39m \u001b[43mTimeSeriesDataFrame\u001b[49m\u001b[38;5;241m.\u001b[39mfrom_path(\n\u001b[1;32m 2\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://autogluon.s3.amazonaws.com/datasets/timeseries/australian_electricity_subset/test.csv\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 3\u001b[0m )\n\u001b[1;32m 4\u001b[0m data\u001b[38;5;241m.\u001b[39mhead()\n",
"\u001b[0;31mNameError\u001b[0m: name 'TimeSeriesDataFrame' is not defined"
]
}
],
"source": [
"data = TimeSeriesDataFrame.from_path(\n",
" \"https://autogluon.s3.amazonaws.com/datasets/timeseries/australian_electricity_subset/test.csv\"\n",
")\n",
"data.head()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'data' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[27], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m prediction_length \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m48\u001b[39m\n\u001b[0;32m----> 2\u001b[0m train_data, test_data \u001b[38;5;241m=\u001b[39m \u001b[43mdata\u001b[49m\u001b[38;5;241m.\u001b[39mtrain_test_split(prediction_length)\n\u001b[1;32m 4\u001b[0m predictor \u001b[38;5;241m=\u001b[39m TimeSeriesPredictor(prediction_length\u001b[38;5;241m=\u001b[39mprediction_length)\u001b[38;5;241m.\u001b[39mfit(\n\u001b[1;32m 5\u001b[0m train_data, presets\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mbolt_small\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 6\u001b[0m )\n",
"\u001b[0;31mNameError\u001b[0m: name 'data' is not defined"
]
}
],
"source": [
"prediction_length = 48\n",
"train_data, test_data = data.train_test_split(prediction_length)\n",
"\n",
"predictor = TimeSeriesPredictor(prediction_length=prediction_length).fit(\n",
" train_data, presets=\"bolt_small\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'predictor' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[28], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m predictions \u001b[38;5;241m=\u001b[39m \u001b[43mpredictor\u001b[49m\u001b[38;5;241m.\u001b[39mpredict(train_data)\n\u001b[1;32m 2\u001b[0m predictor\u001b[38;5;241m.\u001b[39mplot(\n\u001b[1;32m 3\u001b[0m data\u001b[38;5;241m=\u001b[39mdata,\n\u001b[1;32m 4\u001b[0m predictions\u001b[38;5;241m=\u001b[39mpredictions,\n\u001b[1;32m 5\u001b[0m item_ids\u001b[38;5;241m=\u001b[39mdata\u001b[38;5;241m.\u001b[39mitem_ids[:\u001b[38;5;241m2\u001b[39m],\n\u001b[1;32m 6\u001b[0m max_history_length\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m200\u001b[39m,\n\u001b[1;32m 7\u001b[0m );\n",
"\u001b[0;31mNameError\u001b[0m: name 'predictor' is not defined"
]
}
],
"source": [
"predictions = predictor.predict(train_data)\n",
"predictor.plot(\n",
" data=data,\n",
" predictions=predictions,\n",
" item_ids=data.item_ids[:2],\n",
" max_history_length=200,\n",
");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Finetuning"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'TimeSeriesPredictor' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[29], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m predictor \u001b[38;5;241m=\u001b[39m \u001b[43mTimeSeriesPredictor\u001b[49m(prediction_length\u001b[38;5;241m=\u001b[39mprediction_length)\u001b[38;5;241m.\u001b[39mfit(\n\u001b[1;32m 2\u001b[0m train_data\u001b[38;5;241m=\u001b[39mtrain_data,\n\u001b[1;32m 3\u001b[0m hyperparameters\u001b[38;5;241m=\u001b[39m{\n\u001b[1;32m 4\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mChronos\u001b[39m\u001b[38;5;124m\"\u001b[39m: [\n\u001b[1;32m 5\u001b[0m {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodel_path\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mbolt_small\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mag_args\u001b[39m\u001b[38;5;124m\"\u001b[39m: {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname_suffix\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mZeroShot\u001b[39m\u001b[38;5;124m\"\u001b[39m}},\n\u001b[1;32m 6\u001b[0m {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodel_path\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mbolt_small\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfine_tune\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28;01mTrue\u001b[39;00m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mag_args\u001b[39m\u001b[38;5;124m\"\u001b[39m: {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname_suffix\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFineTuned\u001b[39m\u001b[38;5;124m\"\u001b[39m}},\n\u001b[1;32m 7\u001b[0m ]\n\u001b[1;32m 8\u001b[0m },\n\u001b[1;32m 9\u001b[0m time_limit\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m60\u001b[39m, \u001b[38;5;66;03m# time limit in seconds\u001b[39;00m\n\u001b[1;32m 10\u001b[0m enable_ensemble\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[1;32m 11\u001b[0m )\n",
"\u001b[0;31mNameError\u001b[0m: name 'TimeSeriesPredictor' is not defined"
]
}
],
"source": [
"predictor = TimeSeriesPredictor(prediction_length=prediction_length).fit(\n",
" train_data=train_data,\n",
" hyperparameters={\n",
" \"Chronos\": [\n",
" {\"model_path\": \"bolt_small\", \"ag_args\": {\"name_suffix\": \"ZeroShot\"}},\n",
" {\"model_path\": \"bolt_small\", \"fine_tune\": True, \"ag_args\": {\"name_suffix\": \"FineTuned\"}},\n",
" ]\n",
" },\n",
" time_limit=60, # time limit in seconds\n",
" enable_ensemble=False,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'predictor' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[30], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mpredictor\u001b[49m\u001b[38;5;241m.\u001b[39mleaderboard(test_data)\n",
"\u001b[0;31mNameError\u001b[0m: name 'predictor' is not defined"
]
}
],
"source": [
"predictor.leaderboard(test_data)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.20"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading