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
180 changes: 154 additions & 26 deletions lab-intro-probability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability that all passengers get a seat: 0.8845\n",
"Percentage: 88.45%\n"
]
}
],
"source": [
"#code here"
"from scipy.stats import binom\n",
"\n",
"n = 460 \n",
"p_miss = 0.03 \n",
"seats = 450\n",
"\n",
"prob_seats_for_all = 1 - binom.cdf(9, n, p_miss)\n",
"\n",
"print(f\"Probability that all passengers get a seat: {prob_seats_for_all:.4f}\")\n",
"print(f\"Percentage: {prob_seats_for_all*100:.2f}%\")"
]
},
{
Expand Down Expand Up @@ -72,11 +90,25 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability that at least 3 attempts are needed: 0.4900\n",
"Percentage: 49.00%\n"
]
}
],
"source": [
"#code here"
"p_success = 0.3\n",
"\n",
"prob_at_least_3_attempts = (1 - p_success) ** 2\n",
"\n",
"print(f\"Probability that at least 3 attempts are needed: {prob_at_least_3_attempts:.4f}\")\n",
"print(f\"Percentage: {prob_at_least_3_attempts*100:.2f}%\")"
]
},
{
Expand Down Expand Up @@ -107,11 +139,28 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability the server is overwhelmed in one hour: 0.0129\n",
"Percentage: 1.29%\n"
]
}
],
"source": [
"#code here"
"from scipy.stats import poisson\n",
"\n",
"lam = 500 \n",
"capacity = 550\n",
"\n",
"prob_overwhelmed_hour = 1 - poisson.cdf(capacity, lam)\n",
"\n",
"print(f\"Probability the server is overwhelmed in one hour: {prob_overwhelmed_hour:.4f}\")\n",
"print(f\"Percentage: {prob_overwhelmed_hour*100:.2f}%\")"
]
},
{
Expand All @@ -123,11 +172,25 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability the server is overwhelmed at least once in 24 hours: 0.2677\n",
"Percentage: 26.77%\n"
]
}
],
"source": [
"#code here"
"prob_not_overwhelmed_hour = 1 - prob_overwhelmed_hour\n",
"\n",
"prob_overwhelmed_day = 1 - (prob_not_overwhelmed_hour ** 24)\n",
"\n",
"print(f\"Probability the server is overwhelmed at least once in 24 hours: {prob_overwhelmed_day:.4f}\")\n",
"print(f\"Percentage: {prob_overwhelmed_day*100:.2f}%\")"
]
},
{
Expand Down Expand Up @@ -157,10 +220,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability the next customer arrives within 5 minutes: 0.3935\n",
"Percentage: 39.35%\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"mean_time = 10 \n",
"rate = 1 / mean_time\n",
"\n",
"prob_within_5 = 1 - np.exp(-rate * 5)\n",
"\n",
"print(f\"Probability the next customer arrives within 5 minutes: {prob_within_5:.4f}\")\n",
"print(f\"Percentage: {prob_within_5*100:.2f}%\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -173,10 +255,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability an employee can take a break: 0.2231\n",
"Percentage: 22.31%\n"
]
}
],
"source": [
"prob_break = np.exp(-rate * 15)\n",
"\n",
"print(f\"Probability an employee can take a break: {prob_break:.4f}\")\n",
"print(f\"Percentage: {prob_break*100:.2f}%\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -196,11 +292,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability the bird weighs between 140g and 160g: 0.6827\n",
"Percentage: 68.27%\n"
]
}
],
"source": [
"#code here"
"from scipy.stats import norm\n",
"\n",
"mu = 150\n",
"sigma = 10\n",
"\n",
"prob_between = norm.cdf(160, mu, sigma) - norm.cdf(140, mu, sigma)\n",
"\n",
"print(f\"Probability the bird weighs between 140g and 160g: {prob_between:.4f}\")\n",
"print(f\"Percentage: {prob_between*100:.2f}%\")"
]
},
{
Expand All @@ -219,17 +332,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability the component fails within the first 30 hours: 0.4512\n",
"Percentage: 45.12%\n"
]
}
],
"source": [
"#code here"
"mean_lifetime = 50 \n",
"rate = 1 / mean_lifetime\n",
"\n",
"prob_fail_30 = 1 - np.exp(-rate * 30)\n",
"\n",
"print(f\"Probability the component fails within the first 30 hours: {prob_fail_30:.4f}\")\n",
"print(f\"Percentage: {prob_fail_30*100:.2f}%\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -243,7 +371,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down