From 32eac5e1bc4deca336e9e7679cbbb66304ff72a2 Mon Sep 17 00:00:00 2001 From: Marisa Oliveira <163911161+HR-Freak@users.noreply.github.com> Date: Fri, 13 Mar 2026 13:39:10 +0000 Subject: [PATCH] Completed intro to probability lab --- lab-intro-probability.ipynb | 180 ++++++++++++++++++++++++++++++------ 1 file changed, 154 insertions(+), 26 deletions(-) diff --git a/lab-intro-probability.ipynb b/lab-intro-probability.ipynb index 5893fc1..824056d 100644 --- a/lab-intro-probability.ipynb +++ b/lab-intro-probability.ipynb @@ -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}%\")" ] }, { @@ -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}%\")" ] }, { @@ -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}%\")" ] }, { @@ -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}%\")" ] }, { @@ -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", @@ -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", @@ -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}%\")" ] }, { @@ -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" }, @@ -243,7 +371,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.9" + "version": "3.13.5" } }, "nbformat": 4,