Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
218 changes: 192 additions & 26 deletions lab-intro-probability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability that at least 10 passengers don't show up is: 0.8845\n"
]
}
],
"source": [
"#code here"
"#code here\n",
"\n",
"from scipy.stats import binom\n",
"\n",
"# n: total number of tickets sold\n",
"n = 460\n",
"# p: probability of a no-show for each passenger\n",
"p = 0.03\n",
"\n",
"# Compute the probability of at least 10 passengers not showing up\n",
"probability_at_least_10_no_shows = binom.sf(9, n, p) # sf is the survival function, gives P(X > 9)\n",
"\n",
"print(f\"The probability that at least 10 passengers don't show up is: {probability_at_least_10_no_shows:.4f}\")\n"
]
},
{
Expand Down Expand Up @@ -72,11 +92,29 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability of needing at least three attempts is: 0.4900\n"
]
}
],
"source": [
"#code here"
"#code here\n",
"from scipy.stats import geom\n",
"\n",
"# Probability of success on a single attempt\n",
"p = 0.3\n",
"\n",
"# Calculate the probability of needing at least three attempts\n",
"# This is equivalent to 1 - P(X <= 2), where X is the attempt on which the first success occurs\n",
"probability_at_least_three_attempts = 1 - geom.cdf(2, p)\n",
"\n",
"print(f\"The probability of needing at least three attempts is: {probability_at_least_three_attempts:.4f}\")"
]
},
{
Expand Down Expand Up @@ -109,9 +147,26 @@
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability of the website server being overwhelmed is: 0.0129\n"
]
}
],
"source": [
"#code here"
"#code here\n",
"from scipy.stats import poisson\n",
"\n",
"# Average rate (λ) of visits per hour\n",
"lambda_ = 500\n",
"\n",
"# Calculate the probability of more than 550 visits\n",
"probability_overwhelmed = 1 - poisson.cdf(550, lambda_)\n",
"\n",
"print(f\"The probability of the website server being overwhelmed is: {probability_overwhelmed:.4f}\")"
]
},
{
Expand All @@ -123,11 +178,32 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability of the website server being overwhelmed at least once in 24 hours is: 0.2677\n"
]
}
],
"source": [
"#code here"
"#code here\n",
"\n",
"from scipy.stats import poisson\n",
"\n",
"# Average rate (λ) of visits per hour\n",
"lambda_ = 500\n",
"\n",
"# Probability of being overwhelmed in one hour\n",
"probability_overwhelmed_hourly = 1 - poisson.cdf(550, lambda_)\n",
"\n",
"# Probability of being overwhelmed at least once in 24 hours\n",
"probability_overwhelmed_daily = 1 - (1 - probability_overwhelmed_hourly) ** 24\n",
"\n",
"print(f\"The probability of the website server being overwhelmed at least once in 24 hours is: {probability_overwhelmed_daily:.4f}\")"
]
},
{
Expand Down Expand Up @@ -157,10 +233,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability that the next customer will arrive within the next 5 minutes is: 0.3935\n"
]
}
],
"source": [
"import math\n",
"\n",
"# lambda: rate of arrivals per minute\n",
"lambda_rate = 1 / 10\n",
"\n",
"# t: time in minutes (within which we're calculating the probability of arrival)\n",
"t = 5\n",
"\n",
"# Calculate the probability using the exponential distribution CDF formula\n",
"probability_within_5_minutes = 1 - math.exp(-lambda_rate * t)\n",
"\n",
"print(f\"The probability that the next customer will arrive within the next 5 minutes is: {probability_within_5_minutes:.4f}\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -173,10 +270,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability an employee can take a break, with no customers arriving for 15 minutes, is: 0.2231\n"
]
}
],
"source": [
"import math\n",
"\n",
"# lambda: rate of arrivals per minute\n",
"lambda_rate = 1 / 10\n",
"\n",
"# t: time in minutes (no customer arrival period)\n",
"t = 15\n",
"\n",
"# Calculate the probability using the formula for no arrivals\n",
"probability_no_arrival_15_minutes = math.exp(-lambda_rate * t)\n",
"\n",
"print(f\"The probability an employee can take a break, with no customers arriving for 15 minutes, is: {probability_no_arrival_15_minutes:.4f}\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -196,11 +314,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability that a randomly selected bird weighs between 140 and 160 grams is: 0.6827\n"
]
}
],
"source": [
"#code here"
"#code here\n",
"from scipy.stats import norm\n",
"\n",
"# Mean and standard deviation\n",
"mu = 150\n",
"sigma = 10\n",
"\n",
"# Calculate the probability\n",
"probability = norm.cdf(160, mu, sigma) - norm.cdf(140, mu, sigma)\n",
"\n",
"print(f\"The probability that a randomly selected bird weighs between 140 and 160 grams is: {probability:.4f}\")"
]
},
{
Expand All @@ -219,17 +355,47 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability that the component fails within the first 30 hours is: 0.4512\n"
]
}
],
"source": [
"#code here"
"#code here\n",
"import math\n",
"\n",
"# Mean lifetime\n",
"mean_lifetime = 50\n",
"\n",
"# Rate (lambda)\n",
"lambda_rate = 1 / mean_lifetime\n",
"\n",
"# Desired time period\n",
"t = 30\n",
"\n",
"# Probability calculation for P(T <= 30)\n",
"probability_failure_within_30_hours = 1 - math.exp(-lambda_rate * t)\n",
"\n",
"print(f\"The probability that the component fails within the first 30 hours is: {probability_failure_within_30_hours:.4f}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -243,9 +409,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.12.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}