Working on MAT-204 - Good Progress

This commit is contained in:
Win 2024-11-23 20:14:21 +07:00
parent ded8af3b83
commit 029e12c393
8 changed files with 153 additions and 37 deletions

View File

@ -1 +0,0 @@
,slimbook,wins-slimbook,23.11.2024 10:25,file:///home/slimbook/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4;

View File

@ -0,0 +1 @@
,winsdominoes,fedora,23.11.2024 20:14,file:///home/winsdominoes/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4;

View File

@ -1 +0,0 @@
,slimbook,wins-slimbook,23.11.2024 10:26,file:///home/slimbook/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4;

View File

@ -1,8 +1,23 @@
{ {
"cells": [ "cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# MAT-204:00010 - Probability\n",
"Author: Thanawin Pattanaphol - Date: 23th December 2024 - Description: Basic probability calculations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Importing Libraries"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 50, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -12,12 +27,26 @@
"\n", "\n",
"Dat = pd.read_csv('DataLoL.csv')\n", "Dat = pd.read_csv('DataLoL.csv')\n",
"\n", "\n",
"nGame = len(Dat)" "num_games = len(Dat)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Questions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Probability: Blue Team wins"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 51, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -29,13 +58,23 @@
} }
], ],
"source": [ "source": [
"ProbBlueWins = len(Dat[Dat['blueWins'] == 1]) / nGame\n", "# Calculating the probability by diving the amount of games that blue won\n",
"print(\"Probability that Blue Team wins is: \", ProbBlueWins)" "# dividing it by the amount of total games\n",
"# Thus: p = Number of time an event occurs / Total nmumber of possible events\n",
"prob_blue_wins = len(Dat[Dat['blueWins'] == 1]) / num_games\n",
"print(\"Probability that Blue Team wins:\", prob_blue_wins)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Probability: Blue Team wins and kills the dragon"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 52, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -47,13 +86,24 @@
} }
], ],
"source": [ "source": [
"ProbBlueWinsAndDragon = len(Dat[(Dat['blueWins'] == 1) & (Dat['blueDragons'] == 1)]) / nGame\n", "# Doing a similar calculation with the difference being\n",
"print(\"Probability that Blue Team wins and kills the dragon is: \", ProbBlueWinsAndDragon)" "# the number of time an event occurs now only counts\n",
"# the number of times blue team wins and kills the dragon\n",
"\n",
"prob_blue_wins_dragons = len(Dat[(Dat['blueWins'] == 1) & (Dat['blueDragons'] == 1)]) / num_games\n",
"print(\"Probability that Blue Team wins and kills the dragon:\", prob_blue_wins_dragons)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Probability: Blue Team wins and kills the herald"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 53, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -65,13 +115,23 @@
} }
], ],
"source": [ "source": [
"ProbBlueWinsAndHerald = len(Dat[(Dat['blueWins'] == 1) & (Dat['blueHeralds'] == 1)]) / nGame\n", "# Similar calculation but with the number of events that\n",
"print(\"Probability that Blue Team wins and kills the herald is: \", ProbBlueWinsAndHerald)" "# team blue wins and kills the herald\n",
"\n",
"prob_blue_wins_heralds = len(Dat[(Dat['blueWins'] == 1) & (Dat['blueHeralds'] == 1)]) / num_games\n",
"print(\"Probability that Blue Team wins and kills the herald:\", prob_blue_wins_heralds)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Count: All possible cases (Venn Diagram)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 54, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -86,16 +146,19 @@
} }
], ],
"source": [ "source": [
"game_blue_wins = set()\n", "# Declaring variable for each set\n",
"game_blue_dragon = set()\n", "# Loop through the whole games dataset and if the item-\n",
"game_blue_herald = set()\n", "# -matches the condition, add it to the set for that\n",
"# condition list\n",
"\n", "\n",
"for game in range(nGame):\n", "game_blue_wins, game_blue_dragon, game_blue_herald = set()\n",
"\n",
"for game in range(num_games):\n",
" if(Dat['blueWins'][game] == 1):\n", " if(Dat['blueWins'][game] == 1):\n",
" game_blue_wins.add(game)\n", " game_blue_wins.add(game)\n",
" if(Dat['blueDragons'][game] == 1):\n", " else if(Dat['blueDragons'][game] == 1):\n",
" game_blue_dragon.add(game)\n", " game_blue_dragon.add(game)\n",
" if(Dat['blueHeralds'][game] == 1):\n", " else if(Dat['blueHeralds'][game] == 1):\n",
" game_blue_herald.add(game)\n", " game_blue_herald.add(game)\n",
"\n", "\n",
"venn3([game_blue_wins, game_blue_dragon, game_blue_herald], ('A', 'B', 'C'))\n", "venn3([game_blue_wins, game_blue_dragon, game_blue_herald], ('A', 'B', 'C'))\n",
@ -103,9 +166,16 @@
"plt.show()" "plt.show()"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Probability: Each possible events (Venn Diagram)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 55, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -120,6 +190,11 @@
} }
], ],
"source": [ "source": [
"# Setting the variable for each section of the venn diagram\n",
"# Use these values to calculate its probability by\n",
"# diving with the total amount of games\n",
"# Produce venn diagram of the values\n",
"\n",
"count_a = 2055\n", "count_a = 2055\n",
"count_b = 1096\n", "count_b = 1096\n",
"count_c = 564\n", "count_c = 564\n",
@ -130,22 +205,29 @@
"\n", "\n",
"count_abc = 522\n", "count_abc = 522\n",
"\n", "\n",
"p_a = round(2055 / nGame, 3)\n", "p_a = round(2055 / num_games, 3)\n",
"p_b = round(1096 / nGame, 3)\n", "p_b = round(1096 / num_games, 3)\n",
"p_c = round(564 / nGame, 3)\n", "p_c = round(564 / num_games, 3)\n",
"\n", "\n",
"p_ab = round(1770 / nGame, 3)\n", "p_ab = round(1770 / num_games, 3)\n",
"p_ac = round(583 / nGame, 3)\n", "p_ac = round(583 / num_games, 3)\n",
"p_bc = round(188 / nGame, 3)\n", "p_bc = round(188 / num_games, 3)\n",
"\n", "\n",
"p_abc = round(522 / nGame, 3)\n", "p_abc = round(522 / num_games, 3)\n",
"\n", "\n",
"venn = venn3(subsets=(p_a, p_b, p_ab, p_c, p_ac, p_bc, p_abc), set_labels=('A', 'B', 'C'))" "venn = venn3(subsets=(p_a, p_b, p_ab, p_c, p_ac, p_bc, p_abc), set_labels=('A', 'B', 'C'))"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Probability: Blue Team does not manage to do any of the events (Outer White Section)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 56, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -157,12 +239,25 @@
} }
], ],
"source": [ "source": [
"print(\"Probabilty that Blue Team loses, doesn't kill dragons and heralds: \", (nGame - (count_a + count_b + count_c + count_ab + count_abc + count_ac + count_bc)) / nGame)" "# Calculate the total amount of the games in the venn diagram\n",
"# Find the complement of (A B C)\n",
"\n",
"count_all = count_a + count_b + count_c + count_ab + count_abc + count_ac + count_bc\n",
"did_not_win_all = num_games - p_all_wins\n",
"\n",
"print(\"Probabilty that Blue Team loses, doesn't kill dragons and heralds:\", did_not_win_all / num_games)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Probability: Blue Team wins and kills dragon and herald"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 57, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -174,12 +269,22 @@
} }
], ],
"source": [ "source": [
"print(\"Probability that blue team wins, kills dragon and herald: \", p_abc)" "# The probability of this event is essentially the intersection of\n",
"# A (Blue Team Wins), B (Kills Dragon) and C (Kills Herald)\n",
"\n",
"print(\"Probability that blue team wins, kills dragon and herald:\", p_abc)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Probability: Blue Team does not win but kills dragon and the herald "
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 58, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -191,12 +296,22 @@
} }
], ],
"source": [ "source": [
"print(\"Probability that blue team kills dragon and the herald but does not win: \", p_bc)" "# Same with above but only with the intersection between\n",
"# B (Kills Dragon) and C (Kills Herald)\n",
"\n",
"print(\"Probability that blue team does not win but kills dragon and the herald :\", p_bc)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Probability: Blue Team wins but does not kill dragon and herald. "
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 59, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -208,7 +323,9 @@
} }
], ],
"source": [ "source": [
"print(\"Probability that blue team wins without killing the graon and the herald: \", p_a)" "# Same with above but only with the A section (Blue Team wins)\n",
"\n",
"print(\"Probability that blue team wins without killing the dragon and the herald:\", p_a)"
] ]
} }
], ],
@ -228,7 +345,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.12.6" "version": "3.11.2"
} }
}, },
"nbformat": 4, "nbformat": 4,