{ "cells": [ { "cell_type": "markdown", "id": "b3a44695-0827-40d6-9019-53f23ae60173", "metadata": {}, "source": [ "# Pi Ratings" ] }, { "cell_type": "code", "execution_count": 1, "id": "cd283101-4d55-41a2-9eba-4fbed6758cd1", "metadata": {}, "outputs": [], "source": [ "import penaltyblog as pb" ] }, { "cell_type": "code", "execution_count": 2, "id": "69981505-0d55-4c1b-bb41-79cd9a32d066", "metadata": {}, "outputs": [], "source": [ "pi = pb.ratings.PiRatingSystem()" ] }, { "cell_type": "markdown", "id": "3c042824-10c5-4186-929b-80d509e7abde", "metadata": {}, "source": [ "## New Teams Default to a Rating of Zero" ] }, { "cell_type": "code", "execution_count": 3, "id": "0d2521f9-9aea-41a3-90c6-ea53c26d2bd0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0.0, 0.0)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pi.get_team_rating(\"Team A\"), pi.get_team_rating(\"Team B\")" ] }, { "cell_type": "markdown", "id": "8fb73526-00e4-46e0-914a-06d0ee79226a", "metadata": {}, "source": [ "## Predict Match Results" ] }, { "cell_type": "code", "execution_count": 4, "id": "0bd8abfe-f749-4935-91cb-61a0a259146f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'home_win': np.float64(0.3085375387259869),\n", " 'draw': np.float64(0.38292492254802624),\n", " 'away_win': np.float64(0.3085375387259869)}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pi.calculate_match_probabilities(\"Team A\", \"Team B\")" ] }, { "attachments": {}, "cell_type": "markdown", "id": "5f72e549-f8a2-48fa-9912-6027aebc2667", "metadata": {}, "source": [ "## Update Ratings" ] }, { "cell_type": "code", "execution_count": 5, "id": "0fef8ffa-3ab6-4fbe-ab35-7294c0dbdad7", "metadata": {}, "outputs": [], "source": [ "pi.update_ratings(\"Team A\", \"Team B\", 3)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "47dbd6cc-e7c1-4135-9f7e-25caf42f20d7", "metadata": {}, "source": [ "## Get New Ratings" ] }, { "cell_type": "code", "execution_count": 6, "id": "bb1b4e85-1fa3-45a0-906d-f6dbd7167638", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.11538461538461539" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pi.get_team_rating(\"Team A\")" ] } ], "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.13.1" } }, "nbformat": 4, "nbformat_minor": 5 }