Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 190 additions & 24 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"\"\"\""
]
},
Expand All @@ -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 <br>\n",
"P(W) = 10 / 30 = 1/3=0.33 <br>\n",
"2) Taking white ball out after taking a black ball out<br>\n",
"P(W) = 10/29 =0.345 <br>\n",
"3) Taking red ball out after taking a black ball and a red ball out<br>\n",
"P(R) = 11/28 =0.393 <br>\n",
"4) Taking red ball out after taking a black ball and a red ball out with reposition<br>\n",
"P(R) = 12/30 =0.4 <br>*"
]
},
{
Expand All @@ -69,14 +98,18 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"your solution here\n",
"\"\"\""
"R - rainy<br>\n",
"C - cloudy<br>\n",
"P(C|R) = 0.5<br>\n",
"P(C) = 0.4<br>\n",
"P(R) = 3/30 = 0.1<br>\n",
"P(C|R) != P(C), so events are dependent<br>\n",
"**Find**: P(R|C).\n",
"<br><br>\n",
"P(R|C) = P(C|R) * P(R) / P(C) = 0.5 * 0.1 / 0.4 = 0.125\n"
]
},
{
Expand All @@ -102,22 +135,155 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>yes</th>\n",
" <th>no</th>\n",
" <th>total</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>men</th>\n",
" <td>324</td>\n",
" <td>156</td>\n",
" <td>480</td>\n",
" </tr>\n",
" <tr>\n",
" <th>women</th>\n",
" <td>351</td>\n",
" <td>169</td>\n",
" <td>520</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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\") "
]
}
],
Expand All @@ -137,7 +303,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down