From fd1dc5ec907f14f5b8ce18bcead0abf472d6e19e Mon Sep 17 00:00:00 2001 From: PaulinaMamiaga <228375023+PaulinaMamiaga@users.noreply.github.com> Date: Tue, 7 Apr 2026 04:45:27 +0200 Subject: [PATCH] # Update lab-intro-probability.ipynb --- lab-intro-probability.ipynb | 174 ++++++++++++++++++++++++++++++------ 1 file changed, 148 insertions(+), 26 deletions(-) diff --git a/lab-intro-probability.ipynb b/lab-intro-probability.ipynb index 5893fc1..056c3b2 100644 --- a/lab-intro-probability.ipynb +++ b/lab-intro-probability.ipynb @@ -38,11 +38,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability that all 10 passengers will have seats is: 0.8845\n" + ] + } + ], "source": [ - "#code here" + "#code here\n", + "\n", + "from scipy.stats import binom\n", + "\n", + "n = 460\n", + "p_miss = 0.03\n", + "\n", + "prob_seats_for_all = 1 - binom.cdf(9, n, p_miss)\n", + "prob_seats_for_all\n", + "\n", + "print(f\"The probability that all 10 passengers will have seats is: {prob_seats_for_all:.4f}\") \n" ] }, { @@ -72,11 +90,27 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability that the first success occurs on the third attempt or later is: 0.4900\n" + ] + } + ], "source": [ - "#code here" + "#code here\n", + "\n", + "p_success = 0.3\n", + "p_fail = 1 - p_success\n", + "\n", + "prob_at_least_3_attempts = p_fail ** 2\n", + "prob_at_least_3_attempts\n", + "\n", + "print(f\"The probability that the first success occurs on the third attempt or later is: {prob_at_least_3_attempts:.4f}\") \n" ] }, { @@ -107,11 +141,25 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability that the hospital will be overwhelmed in a given hour is: 0.0129\n" + ] + } + ], "source": [ - "#code here" + "#code here\n", + "\n", + "lam = 500\n", + "\n", + "prob_overwhelmed_hour = poisson.sf(550, lam) # P(X > 550)\n", + "prob_overwhelmed_hour\n", + "print(f\"The probability that the hospital will be overwhelmed in a given hour is: {prob_overwhelmed_hour:.4f}\")\n" ] }, { @@ -123,11 +171,24 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability that the hospital will be overwhelmed at least once in a day is: 0.2677\n" + ] + } + ], "source": [ - "#code here" + "#code here\n", + "\n", + "prob_overwhelmed_day = 1 - (1 - prob_overwhelmed_hour) ** 24\n", + "prob_overwhelmed_day\n", + "\n", + "print(f\"The probability that the hospital will be overwhelmed at least once in a day is: {prob_overwhelmed_day:.4f}\") \n" ] }, { @@ -157,10 +218,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability that the next arrival occurs within 5 minutes is: 0.3935\n" + ] + } + ], + "source": [ + "lambda_rate = 1/10 # arrivals per minute\n", + "\n", + "# P(X <= 5)\n", + "prob_within_5 = expon.cdf(5, scale=1/lambda_rate)\n", + "prob_within_5\n", + "\n", + "print(f\"The probability that the next arrival occurs within 5 minutes is: {prob_within_5:.4f}\")\n" + ] }, { "cell_type": "markdown", @@ -173,10 +250,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability that no customer arrives in the next 15 minutes is: 0.2231\n" + ] + } + ], + "source": [ + "# P(X > 15)\n", + "prob_no_customer_15 = expon.sf(15, scale=1/lambda_rate)\n", + "prob_no_customer_15\n", + "\n", + "print(f\"The probability that no customer arrives in the next 15 minutes is: {prob_no_customer_15:.4f}\") \n" + ] }, { "cell_type": "markdown", @@ -196,11 +287,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability that the weight of a randomly selected package is between 140 and 160 grams is: 0.6827\n" + ] + } + ], "source": [ - "#code here" + "#code here\n", + "from scipy.stats import norm\n", + "mean = 150\n", + "std = 10\n", + "\n", + "prob_between = norm.cdf(160, loc=mean, scale=std) - norm.cdf(140, loc=mean, scale=std)\n", + "prob_between\n", + "\n", + "print(f\"The probability that the weight of a randomly selected package is between 140 and 160 grams is: {prob_between:.4f}\")" ] }, { @@ -219,17 +326,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability that the machine fails within 30 minutes is: 0.4512\n" + ] + } + ], "source": [ - "#code here" + "#code here\n", + "\n", + "lambda_rate = 1/50\n", + "\n", + "prob_fail_30 = expon.cdf(30, scale=1/lambda_rate)\n", + "prob_fail_30\n", + "\n", + "print(f\"The probability that the machine fails within 30 minutes is: {prob_fail_30:.4f}\") " ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "base", "language": "python", "name": "python3" }, @@ -243,7 +365,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.9" + "version": "3.13.5" } }, "nbformat": 4,