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
216 changes: 190 additions & 26 deletions lab-intro-probability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Challenge 1\n",
"Probability there are seats for all passengers: 0.884477\n"
]
}
],
"source": [
"#code here"
"import math\n",
"from scipy.stats import binom, geom, poisson, expon, norm\n",
"\n",
"# Challenge 1\n",
"# Ironhack Airlines\n",
"# Seats available for all passengers means at most 450 passengers show up.\n",
"# If 460 tickets are sold and each passenger misses with probability 0.03,\n",
"# then each passenger shows up with probability 0.97.\n",
"\n",
"n_tickets = 460\n",
"p_show = 0.97\n",
"seats = 450\n",
"\n",
"prob_seats_for_all = binom.cdf(seats, n_tickets, p_show)\n",
"\n",
"print(\"Challenge 1\")\n",
"print(f\"Probability there are seats for all passengers: {prob_seats_for_all:.6f}\")"
]
},
{
Expand Down Expand Up @@ -72,11 +97,31 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Challenge 2\n",
"Probability of needing at least 3 attempts: 0.490000\n"
]
}
],
"source": [
"#code here"
"# Ironhack Call Center\n",
"# Success on first attempt probability = 0.3\n",
"# Need at least 3 attempts before success means:\n",
"# first two attempts fail.\n",
"# Probability = (1 - 0.3)^2\n",
"\n",
"p_success = 0.3\n",
"prob_at_least_3_attempts = (1 - p_success) ** 2\n",
"\n",
"print(\"\\nChallenge 2\")\n",
"print(f\"Probability of needing at least 3 attempts: {prob_at_least_3_attempts:.6f}\")\n"
]
},
{
Expand Down Expand Up @@ -107,11 +152,31 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Challenge 3\n",
"Probability server is overwhelmed in one hour: 0.012898\n"
]
}
],
"source": [
"#code here"
"# Ironhack Website\n",
"# Visits per hour follow a Poisson distribution with lambda = 500.\n",
"# Server is overwhelmed if visits exceed 550 in one hour.\n",
"\n",
"lam_hour = 500\n",
"capacity = 550\n",
"\n",
"prob_overwhelmed_one_hour = 1 - poisson.cdf(capacity, lam_hour)\n",
"\n",
"print(\"\\nChallenge 3\")\n",
"print(f\"Probability server is overwhelmed in one hour: {prob_overwhelmed_one_hour:.6f}\")"
]
},
{
Expand All @@ -123,11 +188,23 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability server is overwhelmed at least once during the day: 0.267704\n"
]
}
],
"source": [
"#code here"
"# 1 - P(not overwhelmed in any hour)^24\n",
"\n",
"prob_overwhelmed_some_point_day = 1 - (1 - prob_overwhelmed_one_hour) ** 24\n",
"\n",
"print(f\"Probability server is overwhelmed at least once during the day: {prob_overwhelmed_some_point_day:.6f}\")\n"
]
},
{
Expand Down Expand Up @@ -157,10 +234,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Challenge 4\n",
"Probability next customer arrives within 5 minutes: 0.393469\n",
"Probability an employee can take a break: 0.223130\n"
]
}
],
"source": [
"# Arrivals follow an exponential distribution.\n",
"# Average arrival every 10 minutes means rate lambda = 1/10 per minute.\n",
"\n",
"mean_minutes = 10\n",
"rate = 1 / mean_minutes\n",
"\n",
"# Probability next customer arrives within 5 minutes\n",
"prob_within_5 = expon.cdf(5, scale=mean_minutes)\n",
"\n",
"# Probability no customer arrives for 15 minutes\n",
"# If no customer for 15 minutes, employee can take a break\n",
"prob_break = 1 - expon.cdf(15, scale=mean_minutes)\n",
"\n",
"print(\"\\nChallenge 4\")\n",
"print(f\"Probability next customer arrives within 5 minutes: {prob_within_5:.6f}\")\n",
"print(f\"Probability an employee can take a break: {prob_break:.6f}\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -173,10 +278,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Challenge 4\n",
"Probability next customer arrives within 5 minutes: 0.393469\n",
"Probability an employee can take a break: 0.223130\n"
]
}
],
"source": [
"# Probability next customer arrives within 5 minutes\n",
"prob_within_5 = expon.cdf(5, scale=mean_minutes)\n",
"\n",
"# Probability no customer arrives for 15 minutes\n",
"# If no customer for 15 minutes, employee can take a break\n",
"prob_break = 1 - expon.cdf(15, scale=mean_minutes)\n",
"\n",
"print(\"\\nChallenge 4\")\n",
"print(f\"Probability next customer arrives within 5 minutes: {prob_within_5:.6f}\")\n",
"print(f\"Probability an employee can take a break: {prob_break:.6f}\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -196,11 +323,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Challenge 5\n",
"Probability bird weighs between 140g and 160g: 0.682689\n"
]
}
],
"source": [
"#code here"
"mu = 150\n",
"sigma = 10\n",
"\n",
"prob_between_140_160 = norm.cdf(160, mu, sigma) - norm.cdf(140, mu, sigma)\n",
"\n",
"print(\"\\nChallenge 5\")\n",
"print(f\"Probability bird weighs between 140g and 160g: {prob_between_140_160:.6f}\")\n"
]
},
{
Expand All @@ -219,17 +362,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Challenge 6\n",
"Probability component fails within first 30 hours: 0.451188\n"
]
}
],
"source": [
"#code here"
"mean_lifetime = 50\n",
"prob_fail_30 = expon.cdf(30, scale=mean_lifetime)\n",
"\n",
"print(\"\\nChallenge 6\")\n",
"print(f\"Probability component fails within first 30 hours: {prob_fail_30:.6f}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -243,7 +407,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down