Skip to content

Commit

Permalink
add demo notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
cao-lele committed Aug 12, 2022
1 parent f8bc304 commit 09306a1
Show file tree
Hide file tree
Showing 2 changed files with 425 additions and 0 deletions.
212 changes: 212 additions & 0 deletions sire_arr129.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "05f55287",
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"import warnings\n",
"from dataset import Dataset\n",
"from extrapolations import Extrapolations\n",
"from experiment import Experiment\n",
"\n",
"# comment the following when debugging\n",
"warnings.filterwarnings(\"ignore\")"
]
},
{
"cell_type": "markdown",
"id": "ae408383",
"metadata": {},
"source": [
"## Load ARR129 Dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e49e8ea0",
"metadata": {},
"outputs": [],
"source": [
"# change the company_id if you want to test a different company\n",
"company_id = \"5cf74ff84639c79510ef8491d4725967336ad3627216a50553f030f9c51d93bc\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c88628d",
"metadata": {},
"outputs": [],
"source": [
"# load dataset\n",
"dataset = Dataset()\n",
"dataset.data[dataset.data.id==company_id]"
]
},
{
"cell_type": "markdown",
"id": "2fa33fdb",
"metadata": {},
"source": [
"## Extrapolate for one company"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f4d8447a",
"metadata": {},
"outputs": [],
"source": [
"extrapolations = Extrapolations(\n",
" dataset=dataset,\n",
" org_id=company_id,\n",
" latest_known_dt=datetime.datetime(2018, 5, 1),\n",
" extrapolate_len=36,\n",
" n_trials=10,\n",
" method=\"probability_matching\",\n",
")\n",
"extrapolations.run(params={\"filter_type\": \"smooth\"})\n",
"extrapolations.get_extrapolations_metric_mean_confidence_interval()"
]
},
{
"cell_type": "markdown",
"id": "e280e593",
"metadata": {},
"source": [
"## Evaluation metrics"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0dcc59b3",
"metadata": {},
"outputs": [],
"source": [
"# NLL\n",
"extrapolations.calculate_nll()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "59fc7d11",
"metadata": {},
"outputs": [],
"source": [
"# ACC\n",
"extrapolations.calculate_acc()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "86325e5d",
"metadata": {},
"outputs": [],
"source": [
"# RMSE\n",
"extrapolations.calculate_rmse()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "40f6bdb0",
"metadata": {},
"outputs": [],
"source": [
"# MAPE\n",
"extrapolations.calculate_mape()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7e01c48",
"metadata": {},
"outputs": [],
"source": [
"# PCC\n",
"extrapolations.calculate_pcc()"
]
},
{
"cell_type": "markdown",
"id": "c77c886d",
"metadata": {},
"source": [
"## Extrapolate for all possible dates"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "359d839c",
"metadata": {},
"outputs": [],
"source": [
"experiment = Experiment(\n",
" dataset=dataset,\n",
" org_id=company_id,\n",
" extrapolate_len=36, # months\n",
" n_trials=10,\n",
" method=\"probability_matching\",\n",
" # method=\"simulate:probability_matching\",\n",
")\n",
"experiment.run(params={})"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1cef8bd5",
"metadata": {},
"outputs": [],
"source": [
"# visualize presiction starting from particular date\n",
"date_to_inspect = datetime.datetime(2018, 5, 1)\n",
"experiment.plot_extrapolations_start_from(date_to_inspect)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d43ba330",
"metadata": {},
"outputs": [],
"source": [
"# print the extrapolated results from the same date\n",
"experiment.get_extrapolations_metric_mean_confidence_interval_df_fr(date_to_inspect)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.8.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 09306a1

Please sign in to comment.