{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "6b536cab-71b4-43dd-8312-ee913a4d96d1",
"metadata": {},
"outputs": [],
"source": [
"import evalica\n",
"import pandas as pd\n",
"import plotly.express as px\n",
"from plotly.graph_objects import Figure"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cfed1bc3-7b95-4af6-b234-f94240706e24",
"metadata": {},
"outputs": [],
"source": [
"evalica.__version__"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e647667c-adb8-4f16-9b7c-993cf2739c2b",
"metadata": {},
"outputs": [],
"source": [
"df_food = pd.read_csv(\"food.csv\", dtype=str)\n",
"\n",
"df_food[\"winner\"] = df_food[\"winner\"].map({\n",
" \"left\": evalica.Winner.X,\n",
" \"right\": evalica.Winner.Y,\n",
" \"tie\": evalica.Winner.Draw,\n",
"})\n",
"\n",
"df_food.head(5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "27ebe4b8-d159-4689-be31-ba5e25848e69",
"metadata": {},
"outputs": [],
"source": [
"matrices = evalica.matrices(df_food[\"left\"], df_food[\"right\"], df_food[\"winner\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "42da86e0-c2c6-42c4-9c5e-84d56587fdea",
"metadata": {},
"outputs": [],
"source": [
"pd.DataFrame(matrices.win_matrix, index=matrices.index, columns=matrices.index) # win matrix"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c5dc51f6-bca7-4153-8265-18c019e8a639",
"metadata": {},
"outputs": [],
"source": [
"pd.DataFrame(matrices.tie_matrix, index=matrices.index, columns=matrices.index) # tie matrix"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d273e10b-ede1-4d01-9039-2b4d34bc6164",
"metadata": {},
"outputs": [],
"source": [
"count_result = evalica.counting(df_food[\"left\"], df_food[\"right\"], df_food[\"winner\"])\n",
"count_result.scores.sort_values(ascending=False).to_frame()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d561c08e-4a52-435e-a847-b6adf44ab543",
"metadata": {},
"outputs": [],
"source": [
"bt_result = evalica.bradley_terry(df_food[\"left\"], df_food[\"right\"], df_food[\"winner\"])\n",
"bt_result.scores.sort_values(ascending=False).to_frame()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "64bf8f2b-a08f-46b9-b4df-e5d58d8c8a50",
"metadata": {},
"outputs": [],
"source": [
"newman_result = evalica.newman(df_food[\"left\"], df_food[\"right\"], df_food[\"winner\"])\n",
"newman_result.scores.sort_values(ascending=False).to_frame()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "35cdcc91-d182-4d1c-842e-251052defcd4",
"metadata": {},
"outputs": [],
"source": [
"eigen_result = evalica.eigen(df_food[\"left\"], df_food[\"right\"], df_food[\"winner\"])\n",
"eigen_result.scores.sort_values(ascending=False).to_frame()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "39c5d898-944c-472d-abc2-553c54503adf",
"metadata": {},
"outputs": [],
"source": [
"elo_result = evalica.elo(df_food[\"left\"], df_food[\"right\"], df_food[\"winner\"])\n",
"elo_result.scores.sort_values(ascending=False).to_frame()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66e1a1c5-b32d-4988-92b3-7549fbad3845",
"metadata": {},
"outputs": [],
"source": [
"df_bt_pairwise = evalica.pairwise_frame(bt_result.scores.sort_values(ascending=False))\n",
"\n",
"df_bt_pairwise"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7e7dba72-29d8-4835-b290-2fbccd0d59de",
"metadata": {},
"outputs": [],
"source": [
"def visualize(df_pairwise: pd.DataFrame) -> Figure:\n",
" fig = px.imshow(df_pairwise, color_continuous_scale=\"RdBu\", text_auto=\".2f\")\n",
"\n",
" fig.update_layout(xaxis_title=\"Loser\", yaxis_title=\"Winner\", xaxis_side=\"top\")\n",
"\n",
" fig.update_traces(hovertemplate=\"Winner: %{y}
Loser: %{x}
Fraction of Wins: %{z}\")\n",
"\n",
" return fig"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5241affc-7b81-49f1-9dd0-f2b7f03d2337",
"metadata": {},
"outputs": [],
"source": [
"visualize(df_bt_pairwise)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c92c5a08-3263-4dd4-b8a4-916809a3b0fd",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}