{
"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": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" currentAnswer | \n",
" id | \n",
" openingTimestamp | \n",
" market_creator | \n",
" opening_datetime | \n",
" first_outcome_prob | \n",
" second_outcome_prob | \n",
" kl_divergence | \n",
" off_by_perc | \n",
"
\n",
" \n",
" \n",
" \n",
" | 315 | \n",
" no | \n",
" 0x29462bf8c8f24772cd6da03878a4aee5c5813474 | \n",
" 1724976000 | \n",
" pearl | \n",
" 2024-08-30 02:00:00 | \n",
" 0.9416 | \n",
" 0.0584 | \n",
" 2.840439 | \n",
" 94.16 | \n",
"
\n",
" \n",
" | 323 | \n",
" yes | \n",
" 0x0ad9d4edb0a401ec9a5b4f2ccf7942d28c29d4e3 | \n",
" 1724976000 | \n",
" quickstart | \n",
" 2024-08-30 02:00:00 | \n",
" 0.0499 | \n",
" 0.9501 | \n",
" 2.997734 | \n",
" 95.01 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"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": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" currentAnswer | \n",
" id | \n",
" openingTimestamp | \n",
" market_creator | \n",
" opening_datetime | \n",
" first_outcome_prob | \n",
" second_outcome_prob | \n",
" kl_divergence | \n",
" off_by_perc | \n",
"
\n",
" \n",
" \n",
" \n",
" | 52 | \n",
" no | \n",
" 0x927beda324bfd4514a7b64ab5594451fdaf4796e | \n",
" 1722816000 | \n",
" quickstart | \n",
" 2024-08-05 02:00:00 | \n",
" 0.8792 | \n",
" 0.1208 | \n",
" 2.113619 | \n",
" 87.92 | \n",
"
\n",
" \n",
" | 293 | \n",
" yes | \n",
" 0x90bb15982f2b5a5f044ad8ff49fe20daddfb8ca7 | \n",
" 1724803200 | \n",
" quickstart | \n",
" 2024-08-28 02:00:00 | \n",
" 0.1166 | \n",
" 0.8834 | \n",
" 2.149006 | \n",
" 88.34 | \n",
"
\n",
" \n",
" | 315 | \n",
" no | \n",
" 0x29462bf8c8f24772cd6da03878a4aee5c5813474 | \n",
" 1724976000 | \n",
" pearl | \n",
" 2024-08-30 02:00:00 | \n",
" 0.9416 | \n",
" 0.0584 | \n",
" 2.840439 | \n",
" 94.16 | \n",
"
\n",
" \n",
" | 323 | \n",
" yes | \n",
" 0x0ad9d4edb0a401ec9a5b4f2ccf7942d28c29d4e3 | \n",
" 1724976000 | \n",
" quickstart | \n",
" 2024-08-30 02:00:00 | \n",
" 0.0499 | \n",
" 0.9501 | \n",
" 2.997734 | \n",
" 95.01 | \n",
"
\n",
" \n",
"
\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": 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
}