diff --git a/your-code/main.ipynb b/your-code/main.ipynb index b8b7a9c..4ba2cc6 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -19,12 +19,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'\\nChecking if events are independent:\\nFor independent events, P(A∩B) = P(A) * P(B). 0.1 is not equal to 0.3 multiplied by 0.6, so these events are dependent\\n\\n1) P(A U B) = P(A) + P(B) - P(A∩B) = 0.8, not 0.6, so statement is false\\n2) P(A∩Bcompl) is all of A minus intersection of B and A => P(A) - P(A∩B) = 0.3 - 0.1 = 0.2, so statement is true\\n3) B U Bcompl is full sample, so A ∩ with full sample is just A. P(A) = 0.3, so statement is false\\n4) A compl intersect with B compl is all of sample minus A joined with B => 1 - P(A U B) => 1 - 0.8 = 0.2, so statement is false\\n5) P(not(A∩B)) = 1 - P(A∩B) = 0.9, so statement is true\\n\\n\\n1st statement is false\\n2nd statement is true\\n3rd statement is false\\n4th statement is false\\n5th statement is true\\n\\n'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"\"\"\n", - "your solution here\n", + "Checking if events are independent:\n", + "For independent events, P(A∩B) = P(A) * P(B). 0.1 is not equal to 0.3 multiplied by 0.6, so these events are dependent\n", + "\n", + "1) P(A U B) = P(A) + P(B) - P(A∩B) = 0.8, not 0.6, so statement is false\n", + "2) P(A∩Bcompl) is all of A minus intersection of B and A => P(A) - P(A∩B) = 0.3 - 0.1 = 0.2, so statement is true\n", + "3) B U Bcompl is full sample, so A ∩ with full sample is just A. P(A) = 0.3, so statement is false\n", + "4) A compl intersect with B compl is all of sample minus A joined with B => 1 - P(A U B) => 1 - 0.8 = 0.2, so statement is false\n", + "5) P(not(A∩B)) = 1 - P(A∩B) = 0.9, so statement is true\n", + "\n", + "\n", + "1st statement is false\n", + "2nd statement is true\n", + "3rd statement is false\n", + "4th statement is false\n", + "5th statement is true\n", + "\n", "\"\"\"" ] }, @@ -43,14 +69,17 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "\"\"\"\n", - "your solution here\n", - "\"\"\"" + "*1) Taking white ball out
\n", + "P(W) = 10 / 30 = 1/3=0.33
\n", + "2) Taking white ball out after taking a black ball out
\n", + "P(W) = 10/29 =0.345
\n", + "3) Taking red ball out after taking a black ball and a red ball out
\n", + "P(R) = 11/28 =0.393
\n", + "4) Taking red ball out after taking a black ball and a red ball out with reposition
\n", + "P(R) = 12/30 =0.4
*" ] }, { @@ -69,14 +98,18 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "\"\"\"\n", - "your solution here\n", - "\"\"\"" + "R - rainy
\n", + "C - cloudy
\n", + "P(C|R) = 0.5
\n", + "P(C) = 0.4
\n", + "P(R) = 3/30 = 0.1
\n", + "P(C|R) != P(C), so events are dependent
\n", + "**Find**: P(R|C).\n", + "

\n", + "P(R|C) = P(C|R) * P(R) / P(C) = 0.5 * 0.1 / 0.4 = 0.125\n" ] }, { @@ -102,22 +135,155 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "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", + "
yesnototal
men324156480
women351169520
\n", + "
" + ], + "text/plain": [ + " yes no total\n", + "men 324 156 480\n", + "women 351 169 520" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "import pandas as pd\n", + "dict={\"men\":{\"yes\":324,\"no\":156,\"total\":480},\"women\":{\"yes\":351,\"no\":169,\"total\":520}}\n", + "df=pd.DataFrame.from_dict(dict,orient=\"index\")\n", + "df" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.675" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "\"\"\"\n", - "your solution here\n", - "\"\"\"" + "#Probability of answer being a yes = sum(yes)/sum(total)\n", + "prob_yes=df[\"yes\"].sum()/df[\"total\"].sum()\n", + "prob_yes" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.48" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Probability of responder being a man = sum(total men)/sum(total)\n", + "prob_men=df.loc[\"men\",\"total\"]/df[\"total\"].sum()\n", + "prob_men" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.324" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#intersection of these two events is when men have answered yes:\n", + "prob_intersect=df.loc[\"men\",\"yes\"]/df[\"total\"].sum()\n", + "prob_intersect" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Events are independent\n" + ] + } + ], + "source": [ + "#For independent events, P(A∩B)=P(A)*P(B)\n", + "if prob_intersect == prob_yes * prob_men:\n", + " print(\"Events are independent\")\n", + "else:\n", + " print(\"Events are dependent\") " ] } ], @@ -137,7 +303,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.11.4" } }, "nbformat": 4,