Update rnn_workshop.ipynb
[notebooks.git] / fmda / results_summary.ipynb
blobffa4a12a6e25a0955c0a621ea14f1fca0004329a
2  "cells": [
3   {
4    "cell_type": "code",
5    "execution_count": null,
6    "id": "af683b2e-8e70-403c-ab28-1cfdc314b4d5",
7    "metadata": {},
8    "outputs": [],
9    "source": [
10     "import pandas as pd\n",
11     "from data_funcs import from_json\n",
12     "import matplotlib.pyplot as plt"
13    ]
14   },
15   {
16    "cell_type": "code",
17    "execution_count": null,
18    "id": "365b3157-b5db-4cd1-8095-4f847f24d682",
19    "metadata": {
20     "scrolled": true
21    },
22    "outputs": [],
23    "source": [
24     "rnn = from_json(\"rnn_errs.json\")\n",
25     "kf = from_json(\"kf_errs.json\")"
26    ]
27   },
28   {
29    "cell_type": "code",
30    "execution_count": null,
31    "id": "e4faafed-6678-4164-a6e3-649d01fd63c7",
32    "metadata": {},
33    "outputs": [],
34    "source": [
35     "# Remove \"filename\" key\n",
36     "del rnn['filename']\n",
37     "del kf['filename']"
38    ]
39   },
40   {
41    "cell_type": "code",
42    "execution_count": null,
43    "id": "19b9744c-a4db-4aab-a054-e402269b9f4d",
44    "metadata": {},
45    "outputs": [],
46    "source": [
47     "# Prepare lists to store the extracted values\n",
48     "cases = []\n",
49     "predictions = []\n",
50     "\n",
51     "# Iterate through the dictionary to extract the needed values\n",
52     "for key, value in rnn.items():\n",
53     "    cases.append(value['case'])\n",
54     "    predictions.append(value['errs']['prediction'])\n",
55     "\n",
56     "# Create the DataFrame\n",
57     "df1 = pd.DataFrame({\n",
58     "    'case': cases,\n",
59     "    'prediction': predictions\n",
60     "})\n"
61    ]
62   },
63   {
64    "cell_type": "code",
65    "execution_count": null,
66    "id": "0b961e18-47c9-40a9-9b63-178d7fad27e4",
67    "metadata": {},
68    "outputs": [],
69    "source": [
70     "df1"
71    ]
72   },
73   {
74    "cell_type": "code",
75    "execution_count": null,
76    "id": "690b32ea-4a80-4a44-a7e6-6dd9453041dc",
77    "metadata": {},
78    "outputs": [],
79    "source": [
80     "df2 = pd.DataFrame.from_dict(kf).transpose()\n",
81     "df2.head()"
82    ]
83   },
84   {
85    "cell_type": "code",
86    "execution_count": null,
87    "id": "6c5b2084-879d-4fb9-a25f-a57c3d239dde",
88    "metadata": {},
89    "outputs": [],
90    "source": [
91     "plt.hist(df1.prediction, label = \"RNN\")\n",
92     "plt.hist(df2.errs, label = \"KF\")\n",
93     "plt.legend()"
94    ]
95   },
96   {
97    "cell_type": "code",
98    "execution_count": null,
99    "id": "403c87cb-85c1-4059-9d9c-087d0fd33f9b",
100    "metadata": {},
101    "outputs": [],
102    "source": [
103     "print(df1.prediction.mean())\n",
104     "print(df1.prediction.median())"
105    ]
106   },
107   {
108    "cell_type": "code",
109    "execution_count": null,
110    "id": "0a36faff-9b98-4a80-b464-0973909d5e8f",
111    "metadata": {},
112    "outputs": [],
113    "source": [
114     "print(df2.errs.mean())\n",
115     "print(df2.errs.median())"
116    ]
117   },
118   {
119    "cell_type": "code",
120    "execution_count": null,
121    "id": "4355db09-2232-4526-ba96-42da4cd44ce3",
122    "metadata": {},
123    "outputs": [],
124    "source": []
125   },
126   {
127    "cell_type": "code",
128    "execution_count": null,
129    "id": "5b7a4469-ad9a-4b6a-8982-31873d39e43d",
130    "metadata": {},
131    "outputs": [],
132    "source": []
133   }
134  ],
135  "metadata": {
136   "kernelspec": {
137    "display_name": "Python 3 (ipykernel)",
138    "language": "python",
139    "name": "python3"
140   },
141   "language_info": {
142    "codemirror_mode": {
143     "name": "ipython",
144     "version": 3
145    },
146    "file_extension": ".py",
147    "mimetype": "text/x-python",
148    "name": "python",
149    "nbconvert_exporter": "python",
150    "pygments_lexer": "ipython3",
151    "version": "3.12.5"
152   }
153  },
154  "nbformat": 4,
155  "nbformat_minor": 5