File size: 10,678 Bytes
330cbe3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/cyberosa/.pyenv/versions/hf_dashboards/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"source": [
"import pandas as pd\n",
"import gradio as gr\n",
"import plotly.express as px\n",
"import plotly.graph_objects as go\n",
"from plotly.subplots import make_subplots\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"div_data = pd.read_parquet(\"../data/closed_markets_div.parquet\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"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>currentAnswer</th>\n",
" <th>id</th>\n",
" <th>openingTimestamp</th>\n",
" <th>market_creator</th>\n",
" <th>opening_datetime</th>\n",
" <th>first_outcome_prob</th>\n",
" <th>second_outcome_prob</th>\n",
" <th>kl_divergence</th>\n",
" <th>off_by_perc</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>315</th>\n",
" <td>no</td>\n",
" <td>0x29462bf8c8f24772cd6da03878a4aee5c5813474</td>\n",
" <td>1724976000</td>\n",
" <td>pearl</td>\n",
" <td>2024-08-30 02:00:00</td>\n",
" <td>0.9416</td>\n",
" <td>0.0584</td>\n",
" <td>2.840439</td>\n",
" <td>94.16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>323</th>\n",
" <td>yes</td>\n",
" <td>0x0ad9d4edb0a401ec9a5b4f2ccf7942d28c29d4e3</td>\n",
" <td>1724976000</td>\n",
" <td>quickstart</td>\n",
" <td>2024-08-30 02:00:00</td>\n",
" <td>0.0499</td>\n",
" <td>0.9501</td>\n",
" <td>2.997734</td>\n",
" <td>95.01</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" currentAnswer id \\\n",
"315 no 0x29462bf8c8f24772cd6da03878a4aee5c5813474 \n",
"323 yes 0x0ad9d4edb0a401ec9a5b4f2ccf7942d28c29d4e3 \n",
"\n",
" openingTimestamp market_creator opening_datetime first_outcome_prob \\\n",
"315 1724976000 pearl 2024-08-30 02:00:00 0.9416 \n",
"323 1724976000 quickstart 2024-08-30 02:00:00 0.0499 \n",
"\n",
" second_outcome_prob kl_divergence off_by_perc \n",
"315 0.0584 2.840439 94.16 \n",
"323 0.9501 2.997734 95.01 "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"div_data.loc[div_data[\"off_by_perc\"]>=90]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"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>currentAnswer</th>\n",
" <th>id</th>\n",
" <th>openingTimestamp</th>\n",
" <th>market_creator</th>\n",
" <th>opening_datetime</th>\n",
" <th>first_outcome_prob</th>\n",
" <th>second_outcome_prob</th>\n",
" <th>kl_divergence</th>\n",
" <th>off_by_perc</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>52</th>\n",
" <td>no</td>\n",
" <td>0x927beda324bfd4514a7b64ab5594451fdaf4796e</td>\n",
" <td>1722816000</td>\n",
" <td>quickstart</td>\n",
" <td>2024-08-05 02:00:00</td>\n",
" <td>0.8792</td>\n",
" <td>0.1208</td>\n",
" <td>2.113619</td>\n",
" <td>87.92</td>\n",
" </tr>\n",
" <tr>\n",
" <th>293</th>\n",
" <td>yes</td>\n",
" <td>0x90bb15982f2b5a5f044ad8ff49fe20daddfb8ca7</td>\n",
" <td>1724803200</td>\n",
" <td>quickstart</td>\n",
" <td>2024-08-28 02:00:00</td>\n",
" <td>0.1166</td>\n",
" <td>0.8834</td>\n",
" <td>2.149006</td>\n",
" <td>88.34</td>\n",
" </tr>\n",
" <tr>\n",
" <th>315</th>\n",
" <td>no</td>\n",
" <td>0x29462bf8c8f24772cd6da03878a4aee5c5813474</td>\n",
" <td>1724976000</td>\n",
" <td>pearl</td>\n",
" <td>2024-08-30 02:00:00</td>\n",
" <td>0.9416</td>\n",
" <td>0.0584</td>\n",
" <td>2.840439</td>\n",
" <td>94.16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>323</th>\n",
" <td>yes</td>\n",
" <td>0x0ad9d4edb0a401ec9a5b4f2ccf7942d28c29d4e3</td>\n",
" <td>1724976000</td>\n",
" <td>quickstart</td>\n",
" <td>2024-08-30 02:00:00</td>\n",
" <td>0.0499</td>\n",
" <td>0.9501</td>\n",
" <td>2.997734</td>\n",
" <td>95.01</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" currentAnswer id \\\n",
"52 no 0x927beda324bfd4514a7b64ab5594451fdaf4796e \n",
"293 yes 0x90bb15982f2b5a5f044ad8ff49fe20daddfb8ca7 \n",
"315 no 0x29462bf8c8f24772cd6da03878a4aee5c5813474 \n",
"323 yes 0x0ad9d4edb0a401ec9a5b4f2ccf7942d28c29d4e3 \n",
"\n",
" openingTimestamp market_creator opening_datetime first_outcome_prob \\\n",
"52 1722816000 quickstart 2024-08-05 02:00:00 0.8792 \n",
"293 1724803200 quickstart 2024-08-28 02:00:00 0.1166 \n",
"315 1724976000 pearl 2024-08-30 02:00:00 0.9416 \n",
"323 1724976000 quickstart 2024-08-30 02:00:00 0.0499 \n",
"\n",
" second_outcome_prob kl_divergence off_by_perc \n",
"52 0.1208 2.113619 87.92 \n",
"293 0.8834 2.149006 88.34 \n",
"315 0.0584 2.840439 94.16 \n",
"323 0.9501 2.997734 95.01 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"div_data.loc[div_data[\"kl_divergence\"]>=2.0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"all_markets = closed_markets.copy(deep=True)\n",
" all_markets[\"market_creator\"] = \"all\"\n",
"\n",
" # merging both dataframes\n",
" final_markets = pd.concat([div_data, all_markets], ignore_index=True)\n",
" final_markets = final_markets.sort_values(by=\"opening_datetime\", ascending=True)\n",
"\n",
" # Create the main figure and axis\n",
" fig, ax1 = plt.subplots(figsize=(10, 6))\n",
"\n",
" # Create the boxplot using seaborn\n",
" sns.boxplot(\n",
" data=closed_markets,\n",
" x=\"month_year_week\",\n",
" y=\"kl_divergence\",\n",
" ax=ax1,\n",
" hue=\"market_creator\",\n",
" order=[\"pearl\", \"quickstart\", \"all\"],\n",
" )\n",
"\n",
" # Set labels and title for the main axis\n",
" ax1.set_xlabel(\"Week\")\n",
" ax1.set_ylabel(\"KL Divergence\")\n",
" ax1.set_title(\"KL Divergence Boxplot with Off-by Percentage\")\n",
"\n",
" # Create a secondary y-axis\n",
" ax2 = ax1.twinx()\n",
"\n",
" # Plot the off_by_perc values on the secondary y-axis\n",
" for i, week in enumerate(closed_markets[\"month_year_week\"].unique()):\n",
" off_by_perc = closed_markets[closed_markets[\"month_year_week\"] == week][\n",
" \"off_by_perc\"\n",
" ]\n",
" ax2.scatter([i] * len(off_by_perc), off_by_perc, color=\"red\", alpha=0.01)\n",
"\n",
" # Set label for the secondary y-axis\n",
" ax2.set_ylabel(\"Off-by Percentage\")\n",
"\n",
" # Adjust the layout and display the plot\n",
" plt.tight_layout()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "hf_dashboards",
"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.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|