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
231 changes: 205 additions & 26 deletions lab-intro-probability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0.8844772466215439"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#code here"
"from scipy.stats import binom\n",
"\n",
"n = 460\n",
"p_miss = 0.03\n",
"\n",
"prob_all_have_seats = 1 - binom.cdf(9, n, p_miss)\n",
"prob_all_have_seats"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There is about an 88.45% chance that the airline will still have enough seats for all passengers."
]
},
{
Expand Down Expand Up @@ -72,11 +96,33 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0.48999999999999994"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#code here"
"p_success = 0.3\n",
"p_fail = 1 - p_success\n",
"\n",
"prob_at_least_3_attempts = p_fail**2\n",
"prob_at_least_3_attempts"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There is a 49% chance that the representative will need 3 or more attempts to resolve the complaint."
]
},
{
Expand Down Expand Up @@ -107,11 +153,34 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0.01289822084039205"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#code here"
"from scipy.stats import poisson\n",
"\n",
"lam = 500\n",
"\n",
"prob_overwhelmed = 1 - poisson.cdf(550, lam)\n",
"prob_overwhelmed"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There is about a 1.29% chance that the website server is overwhelmed in any given hour."
]
},
{
Expand All @@ -123,11 +192,30 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0.2677043869515715"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#code here"
"prob_overwhelmed_day = 1 - (1 - prob_overwhelmed)**24\n",
"prob_overwhelmed_day"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There is about a 26.77% chance that the server will be overwhelmed at least once during a full day."
]
},
{
Expand Down Expand Up @@ -157,10 +245,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.3934693402873666"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from scipy.stats import expon\n",
"\n",
"mean_time = 10\n",
"\n",
"prob_within_5 = expon.cdf(5, scale=mean_time)\n",
"prob_within_5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
"source": [
"There is about a 39.35% chance that the next customer arrives within the next 5 minutes."
]
},
{
"cell_type": "markdown",
Expand All @@ -173,10 +286,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.2231301601484298"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prob_break = 1 - expon.cdf(15, scale=mean_time)\n",
"prob_break"
]
},
{
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
"source": [
"There is about a 22.31% chance that no customer arrives for 15 minutes, so the employee can take a break."
]
},
{
"cell_type": "markdown",
Expand All @@ -196,11 +330,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0.6826894921370859"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#code here"
"from scipy.stats import norm\n",
"\n",
"mu = 150\n",
"sigma = 10\n",
"\n",
"prob_between_140_160 = norm.cdf(160, loc=mu, scale=sigma) - norm.cdf(140, loc=mu, scale=sigma)\n",
"prob_between_140_160"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There is about a 68.27% chance that a randomly selected bird weighs between 140g and 160g."
]
},
{
Expand All @@ -219,17 +377,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.4511883639059735"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mean_lifetime = 50\n",
"\n",
"prob_fail_30 = expon.cdf(30, scale=mean_lifetime)\n",
"prob_fail_30"
]
},
{
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"#code here"
"There is about a 45.12% chance that the component fails within the first 30 hours."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -243,7 +422,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down