{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/cyberosa/.pyenv/versions/3.12.2/envs/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": 3, "metadata": {}, "outputs": [], "source": [ "div_data = pd.read_parquet(\"../data/closed_markets_div.parquet\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
currentAnsweridopeningTimestampmarket_creatoropening_datetimefirst_outcome_probsecond_outcome_probkl_divergenceoff_by_perc
0yes0x5cae41dcc8a30d76a31b126c6f3b358b8d0131ca1731542400quickstart2024-11-14 01:00:000.36790.63210.99994463.21
1yes0xf8442bd26cd80d8447bb6203ededc44a77cd2a121731542400quickstart2024-11-14 01:00:000.33680.66321.08826666.32
2yes0xde3a4b0d527013165b1b6b8aae051d223f8b770e1731542400quickstart2024-11-14 01:00:000.44680.55320.80564455.32
3yes0xccadef7757659ce271b209d647c2a51fabd88c771731542400quickstart2024-11-14 01:00:000.68040.31960.38507431.96
4no0x78d0fc5884e74d87b0529e40da2b9490db60e7311731628800quickstart2024-11-15 01:00:000.23580.76420.26892623.58
\n", "
" ], "text/plain": [ " currentAnswer id openingTimestamp \\\n", "0 yes 0x5cae41dcc8a30d76a31b126c6f3b358b8d0131ca 1731542400 \n", "1 yes 0xf8442bd26cd80d8447bb6203ededc44a77cd2a12 1731542400 \n", "2 yes 0xde3a4b0d527013165b1b6b8aae051d223f8b770e 1731542400 \n", "3 yes 0xccadef7757659ce271b209d647c2a51fabd88c77 1731542400 \n", "4 no 0x78d0fc5884e74d87b0529e40da2b9490db60e731 1731628800 \n", "\n", " market_creator opening_datetime first_outcome_prob second_outcome_prob \\\n", "0 quickstart 2024-11-14 01:00:00 0.3679 0.6321 \n", "1 quickstart 2024-11-14 01:00:00 0.3368 0.6632 \n", "2 quickstart 2024-11-14 01:00:00 0.4468 0.5532 \n", "3 quickstart 2024-11-14 01:00:00 0.6804 0.3196 \n", "4 quickstart 2024-11-15 01:00:00 0.2358 0.7642 \n", "\n", " kl_divergence off_by_perc \n", "0 0.999944 63.21 \n", "1 1.088266 66.32 \n", "2 0.805644 55.32 \n", "3 0.385074 31.96 \n", "4 0.268926 23.58 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "div_data.head()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Timestamp('2024-12-28 01:00:00')" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "max(div_data.opening_datetime)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
currentAnsweridopeningTimestampmarket_creatoropening_datetimefirst_outcome_probsecond_outcome_probkl_divergenceoff_by_perc
120yes0x5feab3ad41a2575461b06c5e911d67d3616ee17e1723420800quickstart2024-08-12 02:00:000.90340.09660.1015909.66
148yes0x99a7e8be86a78cf2096a15887e9add122ff113d21723593600quickstart2024-08-14 02:00:000.90500.09500.0998209.50
194no0x34acf849dd645b559ddbf09059df39a1d9b10f181723939200quickstart2024-08-18 02:00:000.08930.91070.0935428.93
\n", "
" ], "text/plain": [ " currentAnswer id \\\n", "120 yes 0x5feab3ad41a2575461b06c5e911d67d3616ee17e \n", "148 yes 0x99a7e8be86a78cf2096a15887e9add122ff113d2 \n", "194 no 0x34acf849dd645b559ddbf09059df39a1d9b10f18 \n", "\n", " openingTimestamp market_creator opening_datetime first_outcome_prob \\\n", "120 1723420800 quickstart 2024-08-12 02:00:00 0.9034 \n", "148 1723593600 quickstart 2024-08-14 02:00:00 0.9050 \n", "194 1723939200 quickstart 2024-08-18 02:00:00 0.0893 \n", "\n", " second_outcome_prob kl_divergence off_by_perc \n", "120 0.0966 0.101590 9.66 \n", "148 0.0950 0.099820 9.50 \n", "194 0.9107 0.093542 8.93 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "div_data.loc[div_data[\"off_by_perc\"]<=10]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
currentAnsweridopeningTimestampmarket_creatoropening_datetimefirst_outcome_probsecond_outcome_probkl_divergenceoff_by_perc
52no0x927beda324bfd4514a7b64ab5594451fdaf4796e1722816000quickstart2024-08-05 02:00:000.87920.12082.11361987.92
293yes0x90bb15982f2b5a5f044ad8ff49fe20daddfb8ca71724803200quickstart2024-08-28 02:00:000.11660.88342.14900688.34
315no0x29462bf8c8f24772cd6da03878a4aee5c58134741724976000pearl2024-08-30 02:00:000.94160.05842.84043994.16
323yes0x0ad9d4edb0a401ec9a5b4f2ccf7942d28c29d4e31724976000quickstart2024-08-30 02:00:000.04990.95012.99773495.01
\n", "
" ], "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": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.20518085, 0.22002342, 1.19369249, 0.64569124, 0.42663767,\n", " 0.57075257, 1.01638735, 0.5982007 , 0.64454751, 0.26958024,\n", " 0.83517168, 0.29249363, 1.09481949, 0.22991644, 0.45381537,\n", " 0.83263916, 0.87299181, 0.77522529, 0.12908415, 0.84653149,\n", " 0.23736926, 0.66281198, 0.5982007 , 1.76960666, 0.52087596,\n", " 0.40481532, 0.82485167, 0.1710256 , 0.31937916, 0.35796149,\n", " 0.28621648, 0.16960278, 0.65488847, 0.34150488, 0.57057563,\n", " 1.38509508, 0.34220866, 1.03310549, 0.68438567, 1.48943512,\n", " 0.61971086, 1.15708922, 0.58429278, 0.14560397, 1.24931891,\n", " 1.24514208, 1.10352433, 0.25000101, 0.93547355, 0.42801751,\n", " 0.13570518, 0.64454751, 2.11361899, 1.06740436, 0.49823851,\n", " 0.51835389, 0.3749844 , 0.23521613, 0.49495227, 0.32739357,\n", " 1.11596193, 0.23041996, 1.30453006, 0.36744704, 0.84257569,\n", " 0.36614825, 0.66281198, 1.20130969, 0.37483891, 1.72484876,\n", " 1.16539332, 0.21245092, 0.8672625 , 0.20998056, 0.57412047,\n", " 0.16972127, 0.17482969, 0.47449369, 1.12639467, 0.13536164,\n", " 0.19820707, 0.52627773, 0.43463649, 0.30693285, 0.49823851,\n", " 0.22639884, 0.48288626, 1.52970294, 0.29008496, 0.16936585,\n", " 0.37950501, 0.63017238, 0.15221921, 0.34814004, 0.36326806,\n", " 0.43866001, 0.43866001, 0.16063835, 0.15864409, 0.3844867 ,\n", " 1.82386952, 0.14768827, 0.16322506, 0.23610215, 1.42628337,\n", " 0.34686607, 0.53273046, 0.22189433, 0.60147999, 0.70218793,\n", " 0.4001791 , 0.2612349 , 1.19964883, 0.74254753, 0.31910394,\n", " 0.72918895, 1.37357559, 0.36759146, 0.25592504, 0.90981177,\n", " 0.10158986, 0.12715179, 0.21418381, 0.301781 , 0.35069287,\n", " 0.33799339, 0.46092497, 0.25967788, 0.22840738, 0.6361999 ,\n", " 0.53939658, 0.74633701, 0.331425 , 0.40466543, 1.10292156,\n", " 0.25993721, 0.31649315, 0.93216608, 1.71813733, 0.81283202,\n", " 0.57839094, 0.28634963, 0.3478568 , 0.23610215, 0.67197295,\n", " 0.86014672, 0.65411879, 1.21334997, 0.09982034, 0.17173776,\n", " 0.43866001, 0.23319389, 0.97577538, 0.83378951, 0.46187674,\n", " 0.59438841, 0.67354065, 0.97259657, 0.50385001, 0.41218765,\n", " 1.43338597, 0.76485803, 0.2527011 , 0.1321609 , 0.61046181,\n", " 1.03930618, 0.49249467, 0.16146067, 0.11160218, 0.16075578,\n", " 0.38816561, 0.56721962, 0.81916402, 0.91854327, 1.7406862 ,\n", " 0.77870507, 0.83863549, 1.10745124, 0.99047563, 0.20874767,\n", " 0.11428915, 0.56229437, 0.82599309, 1.40120497, 0.33561261,\n", " 0.15829258, 0.49823851, 0.5982007 , 1.98050159, 0.8703618 ,\n", " 0.24270871, 0.92533148, 0.55216859, 0.3315643 , 0.09354174,\n", " 0.15012546, 0.39408016, 1.767262 , 1.08975166, 0.52661631,\n", " 0.78372856, 0.66884489, 0.53017835, 0.5186898 , 0.17173776,\n", " 0.64207391, 1.39958226, 0.6806259 , 0.28236291, 0.31800383,\n", " 0.30218676, 0.57075257, 0.5021963 , 0.26709544, 0.47997316,\n", " 1.88190302, 0.21306947, 0.92130327, 0.76528786, 0.40077612,\n", " 0.79540141, 0.80855803, 0.29773241, 1.00430261, 1.23580753,\n", " 0.81170552, 0.9673209 , 0.60990958, 0.448477 , 0.38639805,\n", " 0.52746326, 0.76206863, 0.53802554, 0.22727708, 0.19128158,\n", " 0.42205191, 0.29356602, 1.1017171 , 0.59131287, 0.73334437,\n", " 1.02443289, 1.41510544, 1.57939379, 0.32185952, 0.58770667,\n", " 1.27511083, 1.04782412, 0.17316362, 0.22602269, 0.3400988 ,\n", " 0.46124212, 0.78350962, 0.7001718 , 0.42113728, 0.38038233,\n", " 1.75446368, 0.82393947, 0.34052042, 0.21294573, 0.1468772 ,\n", " 0.28581715, 1.75388582, 0.42205191, 1.09123953, 0.15911297,\n", " 0.13673652, 0.67963883, 0.16652695, 0.26905661, 0.5352891 ,\n", " 0.17876788, 0.73147229, 0.37483891, 1.67825223, 0.43834994,\n", " 0.37062899, 0.31580724, 0.43695578, 0.8672625 , 0.14306238,\n", " 0.58788667, 0.60972557, 1.37753286, 0.12069979, 0.13845779,\n", " 0.93700377, 0.34743208, 0.12658415, 0.23610215, 0.14421685,\n", " 0.56352341, 1.29681935, 0.18248157, 2.14900601, 0.45728486,\n", " 0.47658524, 1.09213332, 0.30924625, 0.22064667, 0.14294701,\n", " 0.47401165, 0.42587192, 0.76614807, 0.36456312, 0.14629826,\n", " 0.80140077, 1.50103204, 0.13478933, 0.75077629, 0.36831384,\n", " 0.19759764, 0.39363536, 0.4807815 , 0.34814004, 0.3831656 ,\n", " 2.84043939, 0.55112692, 0.20028188, 0.94674994, 0.50236155,\n", " 0.3738211 , 0.25000101, 1.25141388, 2.99773428, 0.84793139,\n", " 0.16759059, 0.13433171, 0.42510675, 0.69314718, 0.69555007,\n", " 0.53290083, 0.46092497, 0.53734073, 0.31320503, 0.67393296,\n", " 1.59652169, 0.58950815, 0.22991644, 0.69615169, 1.20932041,\n", " 0.17709524, 0.16877374, 0.71764481, 0.2342045 , 0.34206786,\n", " 1.6419611 , 0.5519949 , 0.46314719, 0.32365473, 0.16463882,\n", " 0.43371027, 0.43417327, 0.1782897 , 0.71192234, 0.37833644,\n", " 0.32158362, 0.34347671, 0.18608864, 0.95815494, 0.57075257,\n", " 1.28989387, 0.22765371, 0.81238127, 0.38404614, 0.47658524,\n", " 0.30734071, 1.81584726, 0.98029606, 0.69314718, 0.66689481,\n", " 1.0782216 , 0.20028188, 0.65277329, 0.28701563, 0.69314718,\n", " 0.69314718, 0.69314718, 0.69314718, 0.2826282 , 0.3569607 ,\n", " 0.18693217, 0.93700377, 0.66009933, 0.33561261, 1.35595916,\n", " 0.5808905 , 0.52915933, 0.95295472, 0.3093825 , 0.46601161,\n", " 0.57128359, 1.32463498, 0.69314718, 0.69314718, 0.72815279,\n", " 0.69314718, 1.51458238, 0.53631439, 0.94623461, 0.7870184 ,\n", " 0.95815494, 0.79053953, 0.36701392, 0.35140315, 0.94494744,\n", " 0.32379296, 0.69314718, 0.84350506, 0.35738948, 0.62735944,\n", " 0.69314718, 0.69314718, 0.62418098, 0.69314718, 0.69314718,\n", " 0.60330648, 0.69314718, 1.29062061, 1.15740734, 0.60239282,\n", " 0.57252374, 0.95139991, 0.85896567, 0.83263916, 0.69314718,\n", " 0.52746326, 0.75395932, 0.57057563, 1.38949949, 0.69314718,\n", " 0.98349948, 0.25721753, 1.67450991, 0.23117572, 0.27878841,\n", " 0.69314718, 0.69314718, 0.69314718, 0.78679874, 0.34488755,\n", " 0.37033931, 0.27984619, 0.29383429, 0.91180083, 0.69314718,\n", " 0.69314718, 0.6953496 , 0.67924428, 0.69314718, 0.69314718,\n", " 0.6909496 , 0.43479094, 0.69314718, 0.69314718, 0.58536959,\n", " 0.8187104 , 0.6953496 , 0.83263916, 0.66904011, 0.69314718,\n", " 0.69314718, 0.43155244, 0.85496048, 0.69314718, 0.69314718,\n", " 0.69314718, 0.6953496 , 0.37994357, 0.67688021, 0.65027928,\n", " 0.63468961, 0.90362133, 0.69314718, 0.90312775, 0.41143288,\n", " 0.69314718, 0.91804226, 0.93521874, 0.45744285, 0.69314718,\n", " 0.38243241, 0.36528332, 0.69314718, 0.69314718, 0.69314718,\n", " 0.69314718, 0.69314718, 0.75502258, 0.69314718, 0.34644177,\n", " 0.43216849, 1.2265593 , 0.69314718, 1.30195321, 0.67119001,\n", " 0.35524739, 0.69314718, 0.67119001, 0.44613086, 0.71559731,\n", " 0.69314718, 0.76314055, 0.26565969, 0.69314718, 0.57075257,\n", " 0.86132917, 0.57075257, 0.55025969, 1.25421402, 0.35610368,\n", " 0.69314718, 0.69314718, 0.39245017, 0.69314718, 0.54731673,\n", " 0.25128586, 1.50688132, 0.31512179, 0.29948478, 0.37687765,\n", " 0.4764242 , 0.69314718, 0.95659203, 0.31704223, 0.15712176,\n", " 0.18693217, 0.14629826, 0.69314718, 0.29437106, 0.4405225 ,\n", " 0.73022619, 1.55211285, 0.2010152 , 0.16699954, 0.8603831 ,\n", " 1.83320666, 0.95633178, 0.83471074, 0.26513811, 0.69314718,\n", " 1.07704651, 0.5163408 , 0.35197174, 0.69314718, 0.83263916,\n", " 0.30979136, 0.92861638, 0.69314718, 0.69314718, 0.27338477,\n", " 0.69314718, 0.69314718, 0.69314718, 0.82211756, 0.69314718,\n", " 0.69735603, 0.29557984, 0.81215597, 0.36571569, 0.69314718,\n", " 1.24132859, 0.69314718, 0.21815601, 0.30584604, 0.28861584,\n", " 0.31717954, 0.55216859, 0.29894526, 0.69314718, 0.69856181,\n", " 0.69314718, 1.38909829, 0.35496213, 0.69314718, 0.27680808,\n", " 0.69314718, 0.69314718, 0.69314718, 0.67119001, 0.69314718,\n", " 0.27931716, 0.69314718, 0.69314718, 0.57075257, 0.69314718,\n", " 0.49298571, 0.2182804 , 1.05096564, 0.65932563, 1.03704693,\n", " 0.57075257, 0.49036962, 0.53597251, 0.4764242 , 0.73459437,\n", " 0.50005055, 0.4764242 , 0.69314718, 0.64588199, 0.37965117,\n", " 0.5608916 , 0.69314718, 0.68617157, 1.30822283, 0.93547355,\n", " 0.69314718, 0.97021907, 0.65027928, 1.09871229, 0.25077172,\n", " 0.69314718, 0.69314718, 0.92558378, 0.69314718, 0.57110655,\n", " 0.69314718, 0.69314718, 0.69314718, 0.83263916, 0.69314718,\n", " 0.69314718, 0.53682743, 0.69314718, 1.33370191, 1.13072234,\n", " 0.28090509, 0.72278199, 0.71559731, 0.69314718, 0.86988436,\n", " 0.69314718, 0.61766872, 0.33017212, 0.69314718, 0.69314718,\n", " 0.69314718])" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "div_data.kl_divergence.values" ] }, { "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 }