diff --git a/your-code/lab.ipynb b/your-code/lab.ipynb new file mode 100644 index 0000000..e049100 --- /dev/null +++ b/your-code/lab.ipynb @@ -0,0 +1,388 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Introduction To Probability\n", + "## Challenge 1\n", + "\n", + "A and B are events of a probability space with $(\\omega, \\sigma, P)$ such that $P(A) = 0.3$, $P(B) = 0.6$ and $P(A \\cap B) = 0.1$\n", + "\n", + "Which of the following statements are false?\n", + "* $P(A \\cup B) = 0.6$\n", + "* $P(A \\cap B^{C}) = 0.2$\n", + "* $P(A \\cap (B \\cup B^{C})) = 0.4$\n", + "* $P(A^{C} \\cap B^{C}) = 0.3$\n", + "* $P((A \\cap B)^{C}) = 0.9$" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'1.P(AUB)=0.3+0.6-0.1 = 0.8. - False\\n2.P(A∩B^C)= P(A)-P(A∩B)= 0.3-0.1 =0.2 - True\\n3.P(A∩(BUB^C))= P(A)∩P(BUB^C)= P(A)∩P(w)= P(A)=0.3 - False\\n4.𝑃(𝐴𝐶∩𝐵𝐶)=0.3 = 1-P(AUB)=1-(0.3+0.6-0.1)=0.2 - False \\n5.𝑃((𝐴∩𝐵)𝐶)=0.9 = 1- P(A∩B)=0.9 - True '" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"1.P(AUB)=0.3+0.6-0.1 = 0.8. - False\n", + "2.P(A∩B^C)= P(A)-P(A∩B)= 0.3-0.1 =0.2 - True\n", + "3.P(A∩(BUB^C))= P(A)∩P(BUB^C)= P(A)∩P(w)= P(A)=0.3 - False\n", + "4.𝑃(𝐴𝐶∩𝐵𝐶)=0.3 = 1-P(AUB)=1-(0.3+0.6-0.1)=0.2 - False \n", + "5.𝑃((𝐴∩𝐵)𝐶)=0.9 = 1- P(A∩B)=0.9 - True \"\"\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Challenge 2\n", + "There is a box with 10 white balls, 12 red balls and 8 black balls. Calculate the probability of:\n", + "* Taking a white ball out.\n", + "* Taking a white ball out after taking a black ball out.\n", + "* Taking a red ball out after taking a black and a red ball out.\n", + "* Taking a red ball out after taking a black and a red ball out with reposition.\n", + "\n", + "**Hint**: Reposition means putting back the ball into the box after taking it out." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "A= \"taking a white ball\"\n", + "B= \"taking a red ball\"\n", + "C= \"taking a black ball\"\n", + "\n", + "#P(A) ==10/30\n", + "#P(B) ==12/30\n", + "#P(C) ==8/30" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Probability of taking a white ball out. = 10/30 =1/3'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Probability of taking a white ball out. = 10/30 =1/3\"" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Probability of taking a white ball out after taking a black ball out = 10/29'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Probability of taking a white ball out after taking a black ball out = 10/29\"" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Probability of taking a red ball out after taking a black and a red ball out = 7/28'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Probability of taking a red ball out after taking a black and a red ball out = 7/28\"" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Probability of taking a red ball out after taking a black and a red ball out with reposition = 12/30 = 2/5'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Probability of taking a red ball out after taking a black and a red ball out with reposition = 12/30 = 2/5\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Challenge 3\n", + "\n", + "You are planning to go on a picnic today but the morning is cloudy. You hate rain so you don't know whether to go out or stay home! To help you make a decision, you gather the following data about rainy days:\n", + "\n", + "* Knowing that it is a rainy day, the probability of cloudy is 50%!\n", + "* The probability of any day (rainy or not) starting off cloudy is 40%. \n", + "* This month is usually dry so only 3 of 30 days (10%) tend to be rainy. \n", + "\n", + "What is the probability of rain, given the day started cloudy?" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'\\nA= \"rainy day\"\\nB= \"cloudy day\"\\n\\nP(A\\\\B) = 0.5\\nP(B) = 0.4\\nP(A) = 0.1\\n\\nP(B/A)=0.5= P(B∩A)/P(A)=0.5*0.1=0.05\\nP(A/B)=P(A∩B)/P(B)=0.05/0.4 = 0.125 '" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "A= \"rainy day\"\n", + "B= \"cloudy day\"\n", + "\n", + "P(A\\B) = 0.5\n", + "P(B) = 0.4\n", + "P(A) = 0.1\n", + "\n", + "P(B/A)=0.5= P(B∩A)/P(A)=0.5*0.1=0.05\n", + "P(A/B)=P(A∩B)/P(B)=0.05/0.4 = 0.125 \"\"\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Challenge 4\n", + "\n", + "One thousand people were asked through a telephone survey whether they thought more street lighting is needed at night or not.\n", + "\n", + "Out of the 480 men that answered the survey, 324 said yes and 156 said no. On the other hand, out of the 520 women that answered, 351 said yes and 169 said no. \n", + "\n", + "We wonder if men and women have a different opinions about the street lighting matter. Is gender relevant or irrelevant to the question?\n", + "\n", + "Consider the following events:\n", + "- The answer is yes, so the person that answered thinks that more street lighting is needed.\n", + "- The person who answered is a man.\n", + "\n", + "We want to know if these events are independent, that is, if the fact of wanting more light depends on whether one is male or female. Are these events independent or not?\n", + "\n", + "**Hint**: To clearly compare the answers by gender, it is best to place the data in a table." + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Yes gender is important.'" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#We wonder if men and women have a different opinions about the street lighting matter. Is gender relevant or irrelevant to the question?\n", + "\"Yes gender is important.\"" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "# your code here\n", + "men_yes = 324\n", + "men_no = 156\n", + "total_men = 480\n", + "women_yes = 351\n", + "women_no = 169\n", + "total_women = 520\n", + "total = total_men + total_women" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "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", + "
GenderYesNoTotal
0Men324156480
1Women351169520
2Total6753251000
\n", + "
" + ], + "text/plain": [ + " Gender Yes No Total\n", + "0 Men 324 156 480\n", + "1 Women 351 169 520\n", + "2 Total 675 325 1000" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pandas as pd \n", + "\n", + "data = {\n", + " 'Gender': ['Men', 'Women', 'Total'],\n", + " 'Yes': [men_yes, women_yes, men_yes + women_yes],\n", + " 'No': [men_no, women_no, men_no + women_no],\n", + " 'Total': [total_men, total_women, total]\n", + "}\n", + "\n", + "# Create a Pandas DataFrame\n", + "table = pd.DataFrame(data)\n", + "table" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#We want to know if these events are independent, that is,\n", + "#if the fact of wanting more light depends on whether one is male or female. Are these events independent or not?\n", + "\n", + "#A= \"wanting more light = answer yes\"\n", + "#A' = \"answer is no\"\n", + "#B= \"is a men\" \n", + "#B'= \"is a women\"\n", + "\n", + "#P(A∩B)=324/1000=0.324\n", + "#Independent ? P(A∩B)= P(A)*P(B)= (675/1000)*(480/1000)=0.324 \n", + "#So,the conclusion is that \"answer yes\" and \"being a male\" are independent" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/main.ipynb b/your-code/main.ipynb deleted file mode 100644 index b8b7a9c..0000000 --- a/your-code/main.ipynb +++ /dev/null @@ -1,145 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Introduction To Probability\n", - "## Challenge 1\n", - "\n", - "A and B are events of a probability space with $(\\omega, \\sigma, P)$ such that $P(A) = 0.3$, $P(B) = 0.6$ and $P(A \\cap B) = 0.1$\n", - "\n", - "Which of the following statements are false?\n", - "* $P(A \\cup B) = 0.6$\n", - "* $P(A \\cap B^{C}) = 0.2$\n", - "* $P(A \\cap (B \\cup B^{C})) = 0.4$\n", - "* $P(A^{C} \\cap B^{C}) = 0.3$\n", - "* $P((A \\cap B)^{C}) = 0.9$" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\"\"\"\n", - "your solution here\n", - "\"\"\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 2\n", - "There is a box with 10 white balls, 12 red balls and 8 black balls. Calculate the probability of:\n", - "* Taking a white ball out.\n", - "* Taking a white ball out after taking a black ball out.\n", - "* Taking a red ball out after taking a black and a red ball out.\n", - "* Taking a red ball out after taking a black and a red ball out with reposition.\n", - "\n", - "**Hint**: Reposition means putting back the ball into the box after taking it out." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\"\"\"\n", - "your solution here\n", - "\"\"\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 3\n", - "\n", - "You are planning to go on a picnic today but the morning is cloudy. You hate rain so you don't know whether to go out or stay home! To help you make a decision, you gather the following data about rainy days:\n", - "\n", - "* Knowing that it is a rainy day, the probability of cloudy is 50%!\n", - "* The probability of any day (rainy or not) starting off cloudy is 40%. \n", - "* This month is usually dry so only 3 of 30 days (10%) tend to be rainy. \n", - "\n", - "What is the probability of rain, given the day started cloudy?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\"\"\"\n", - "your solution here\n", - "\"\"\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 4\n", - "\n", - "One thousand people were asked through a telephone survey whether they thought more street lighting is needed at night or not.\n", - "\n", - "Out of the 480 men that answered the survey, 324 said yes and 156 said no. On the other hand, out of the 520 women that answered, 351 said yes and 169 said no. \n", - "\n", - "We wonder if men and women have a different opinions about the street lighting matter. Is gender relevant or irrelevant to the question?\n", - "\n", - "Consider the following events:\n", - "- The answer is yes, so the person that answered thinks that more street lighting is needed.\n", - "- The person who answered is a man.\n", - "\n", - "We want to know if these events are independent, that is, if the fact of wanting more light depends on whether one is male or female. Are these events independent or not?\n", - "\n", - "**Hint**: To clearly compare the answers by gender, it is best to place the data in a table." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\"\"\"\n", - "your solution here\n", - "\"\"\"" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.7.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}