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
224 changes: 199 additions & 25 deletions lab-intro-probability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
"Welcome to this Intro to Probability lab, where we explore decision-making scenarios through the lens of probability and strategic analysis. In the business world, making informed decisions is crucial, especially when faced with uncertainties. This lab focuses on scenarios where probabilistic outcomes play a significant role in shaping strategies and outcomes. Students will engage in exercises that require assessing and choosing optimal paths based on data-driven insights. The goal is to enhance your skills by applying probability concepts to solve real-world problems."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from scipy.stats import binom\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from scipy.stats import geom"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -40,9 +53,31 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"np.float64(0.8844772466215431)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#code here"
"# total seats = 450\n",
"# airline sells 460 seats\n",
"# 3% chane of missing flight so 97% chance of showing up\n",
"\n",
"\n",
"p = 0.97 #probability of people taking their flights\n",
"n = 460 #seats avalable \n",
"capacity = 450\n",
"\n",
"binom_dist = binom(n,p)\n",
"\n",
"binom_dist.cdf(450)"
]
},
{
Expand Down Expand Up @@ -72,11 +107,28 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability of needing at least 3 attempts: 0.4900\n"
]
}
],
"source": [
"#code here"
"#code here\n",
"\n",
"p = 0.3\n",
"\n",
"geom_dist = geom(p)\n",
"\n",
"probability = 1 - geom_dist.cdf(2)\n",
"\n",
"\n",
"print(f\"Probability of needing at least 3 attempts: {probability:.4f}\")\n"
]
},
{
Expand Down Expand Up @@ -107,11 +159,29 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 18,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability of server being overwhelmed: 0.0129\n"
]
}
],
"source": [
"#code here"
"from scipy.stats import poisson\n",
"\n",
"lambda_rate = 500 # average visits per hour\n",
"capacity = 550 #server can handel \n",
"\n",
"\n",
"poisson_dist = poisson(lambda_rate)\n",
"\n",
"probability = 1 - poisson_dist.cdf(550)\n",
"\n",
"print(f\"Probability of server being overwhelmed: {probability:.4f}\")"
]
},
{
Expand All @@ -123,11 +193,36 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 20,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability overwhelmed at least once in 24 hours: 0.2677\n"
]
}
],
"source": [
"#code here"
"lambda_rate = 500 # average visits per hour\n",
"capacity = 550 # server capacity\n",
" # number of hours in a day\n",
"\n",
"# Create Poisson distribution\n",
"poisson_dist = poisson(lambda_rate)\n",
"\n",
"# P(NOT overwhelmed in one hour) = P(X ≤ 550)\n",
"prob_not_overwhelmed_one_hour = poisson_dist.cdf(550)\n",
"\n",
"# P(NOT overwhelmed in ALL 24 hours) = (prob for one hour)^24\n",
"prob_not_overwhelmed_all_day = prob_not_overwhelmed_one_hour ** 24\n",
"\n",
"# P(overwhelmed at least once) = 1 - P(never overwhelmed)\n",
"probability = 1 - prob_not_overwhelmed_all_day\n",
"\n",
"\n",
"print(f\"Probability overwhelmed at least once in 24 hours: {probability:.4f}\")"
]
},
{
Expand Down Expand Up @@ -157,10 +252,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability customer arrives within 5 minutes: 0.3935\n"
]
}
],
"source": [
"from scipy.stats import expon\n",
"\n",
"mean_time = 10 # average time between customers (minutes)\n",
"scale = mean_time # scale parameter for exponential distribution\n",
"\n",
"# Create exponential distribution\n",
"expon_dist = expon(scale=scale)\n",
"\n",
"# P(X ≤ 5) = probability customer arrives within 5 minutes\n",
"probability = expon_dist.cdf(5)\n",
"\n",
"print(f\"Probability customer arrives within 5 minutes: {probability:.4f}\")\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -173,10 +289,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability of no customer for 15+ minutes: 0.2231\n"
]
}
],
"source": [
"\n",
"probability = 1 - expon_dist.cdf(15)\n",
"\n",
"print(f\"Probability of no customer for 15+ minutes: {probability:.4f}\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -196,11 +325,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability weight is between 140 and 160 grams: 0.6827\n"
]
}
],
"source": [
"#code here"
"#code here\n",
"\n",
"from scipy.stats import norm\n",
"\n",
"mean = 150 \n",
"std_dev = 10\n",
"\n",
"# Create normal distribution\n",
"norm_dist = norm(loc=mean, scale=std_dev)\n",
"\n",
"# P(140 < X < 160) = P(X ≤ 160) - P(X ≤ 140)\n",
"probability = norm_dist.cdf(160) - norm_dist.cdf(140)\n",
"\n",
"print(f\"Probability weight is between 140 and 160 grams: {probability:.4f}\")\n",
"\n"
]
},
{
Expand All @@ -219,17 +370,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability component fails within 30 hours: 0.4512\n"
]
}
],
"source": [
"#code here"
"#code here\n",
"\n",
"\n",
"from scipy.stats import expon\n",
"\n",
"mean_lifetime = 50 # mean lifetime in hours\n",
"scale = mean_lifetime\n",
"\n",
"# Create exponential distribution\n",
"expon_dist = expon(scale=scale)\n",
"\n",
"# P(X ≤ 30) = probability component fails within 30 hours\n",
"probability = expon_dist.cdf(30)\n",
"\n",
"\n",
"print(f\"Probability component fails within 30 hours: {probability:.4f}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "data-analytics",
"language": "python",
"name": "python3"
},
Expand All @@ -243,7 +417,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.9.23"
}
},
"nbformat": 4,
Expand Down