From aefc6ac92ad2f0775ce5dcbbbfb046220ce280fc Mon Sep 17 00:00:00 2001 From: YaraLis Date: Mon, 20 Nov 2023 03:49:14 +0000 Subject: [PATCH] lab done --- your-code/main.ipynb | 306 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 290 insertions(+), 16 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index b8b7a9c..66778ca 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -19,12 +19,110 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.7999999999999999\n" + ] + } + ], + "source": [ + "#𝑃(𝐴βˆͺ𝐡)=0.6\n", + "A = 0.3\n", + "B = 0.6\n", + "unionAB=A+B-0.1\n", + "print(unionAB)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.16666666666666669\n" + ] + } + ], + "source": [ + "#𝑃(𝐴∩𝐡𝐢)=0.2\n", + "\n", + "cond_AB=0.1/B\n", + "print(cond_AB)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.27999999999999997\n" + ] + } + ], + "source": [ + "#𝑃(𝐴𝐢∩𝐡𝐢)=0.3\n", + "\n", + "AC=1-A\n", + "BC=1-B\n", + "AcnBc=AC*BC\n", + "print(AcnBc)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.9" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#𝑃((𝐴∩𝐡)𝐢)=0.9\n", + "1-0.1\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'\\n𝑃(𝐴βˆͺ𝐡)=0.6 is false\\n𝑃(𝐴∩𝐡𝐢)=0.2 is false\\n𝑃(𝐴∩(𝐡βˆͺ𝐡𝐢))=0.4 is false\\n\\n'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"\"\"\n", - "your solution here\n", + "𝑃(𝐴βˆͺ𝐡)=0.6 is false\n", + "𝑃(𝐴∩𝐡𝐢)=0.2 is false\n", + "𝑃(𝐴∩(𝐡βˆͺ𝐡𝐢))=0.4 is false\n", + "#𝑃(𝐴𝐢∩𝐡𝐢)=0.3 is false\n", "\"\"\"" ] }, @@ -42,14 +140,114 @@ "**Hint**: Reposition means putting back the ball into the box after taking it out." ] }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.3333333333333333" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "W=10\n", + "R=12\n", + "B=8\n", + "S=sum([W,R,B])\n", + "W/S" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.36666666666666664" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "W=9\n", + "R=11\n", + "B=6\n", + "\n", + "R/S" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], + "source": [ + "W=9\n", + "R=12\n", + "B=7\n", + "S=sum(W,R,B)\n", + "9/S" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.39285714285714285" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "W=10\n", + "R=11\n", + "B=7\n", + "S=sum([W,R,B])\n", + "R/S" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'\\nyour solution here\\n'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"\"\"\n", - "your solution here\n", + "#1. Taking a white ball out 0.33\n", + "#2. Taking a white ball out after taking a black ball out. 0.3\n", + "#3. Taking a red ball out after taking a black and a red ball out. 0.36\n", + "#4. Taking a red ball out after taking a black and a red ball out with reposition.0.39\n", "\"\"\"" ] }, @@ -70,15 +268,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'\\nyour solution here\\n'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"\"\"\n", - "your solution here\n", + "P(R|C)=0.5\n", + "C=0.4\n", + "R=0.1\n", + "|R n C| = (R|C) * (R)/(C)\n", + "the answer is 0.125\n", + "\n", "\"\"\"" ] }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.125" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(0.5*0.1)/0.4" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -102,28 +336,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The events of wanting more street lighting and being a man are independent.\n" + ] + } + ], "source": [ - "# your code here" + "import pandas as pd\n", + "\n", + "data = {'Gender':['Men', 'Women'],\n", + " 'Total': [480, 520],\n", + " 'Yes':[324, 351],\n", + " 'No':[156, 160]}\n", + "\n", + "survey=pd.DataFrame(data)\n", + "survey.set_index('Gender', inplace=True)\n", + "survey\n", + "\n", + "total_responses = survey['Total'].sum()\n", + "prob_A = survey['Yes'].sum() / total_responses\n", + "prob_B = survey.loc['Men', 'Total'] / total_responses\n", + "\n", + "prob_A_given_B = survey.loc['Men', 'Yes'] / survey.loc['Men', 'Total']\n", + "prob_A_given_B\n", + "\n", + "if prob_A_given_B == prob_A:\n", + " print(\"The events of wanting more street lighting and being a man are independent.\")\n", + "else:\n", + " print(\"The events of wanting more street lighting and being a man are not independent.\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'\\nyour solution here\\n'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "\"\"\"\n", - "your solution here\n", + "\"\"\"\"0.675 probability the person who answered is a man. \n", + "The events of wanting more street lighting and being a man are independent\n", "\"\"\"" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -137,7 +411,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.11.5" } }, "nbformat": 4,