From 85684552fd5b9317cf676b4b91bcd2f971b2351d Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 22 Mar 2026 10:47:43 +0100 Subject: [PATCH] Solved lab --- lab-intro-probability.ipynb | 173 ++++++++++++++++++++++++++++++------ 1 file changed, 146 insertions(+), 27 deletions(-) diff --git a/lab-intro-probability.ipynb b/lab-intro-probability.ipynb index 5893fc1..c922bc9 100644 --- a/lab-intro-probability.ipynb +++ b/lab-intro-probability.ipynb @@ -38,11 +38,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " The chance that they have seats for all passangers is 88.45%\n" + ] + } + ], "source": [ - "#code here" + "from scipy.stats import binom\n", + "\n", + "seats = 450 # K = Kapacity, Korte, Konstant... The MAX IF there is one. In the notebook K was 3 labs=30.000\n", + "K= seats\n", + "\n", + "tickets_sold = 460 # N = Number of trials\n", + "N= tickets_sold\n", + "\n", + "probability_of_attending = 0.97 # P \n", + "P= probability_of_attending\n", + "\n", + "chance_to_have_seats = binom.cdf(K,N,P) \n", + "\n", + "print(f\" The chance that they have seats for all passangers is {chance_to_have_seats*100:.2f}%\")" ] }, { @@ -72,11 +93,24 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Probability that the representative needs to make at least three attempts before successfully resolving a customer complaint: 49.0%\n", + "Or which is the same, 0.7 * 0.7 = 0.49 --> 49%\n" + ] + } + ], "source": [ - "#code here" + "from scipy.stats import geom\n", + "p = 0.3\n", + "probability = 1 - geom.cdf(2, p)\n", + "print(f\"Probability that the representative needs to make at least three attempts before successfully resolving a customer complaint: {probability*100}%\")\n", + "print(\"Or which is the same, 0.7 * 0.7 = 0.49 --> 49%\")" ] }, { @@ -107,11 +141,22 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability of the website server being overwhelmed is 0.01\n" + ] + } + ], "source": [ - "#code here" + "from scipy.stats import poisson\n", + "mu = 500 # average\n", + "poisson_dist = poisson(mu)\n", + "print(f\"The probability of the website server being overwhelmed is {1 - poisson_dist.cdf(550): .2f}\")" ] }, { @@ -123,11 +168,22 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Probability of being overwhelmed at some point during a day: 21.43%\n" + ] + } + ], "source": [ - "#code here" + "probab_not_being_overwhelmed_1h = 1-.01 \n", + "probab_not_being_overwhelmed_in_24h = probab_not_being_overwhelmed_1h **24\n", + "probab_overwhelmed_24h = 1- probab_not_being_overwhelmed_in_24h\n", + "print(f\"Probability of being overwhelmed at some point during a day: {probab_overwhelmed_24h*100:.2f}%\")" ] }, { @@ -157,10 +213,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability that the next customer will arrive within the next 5 minutes is 39.35%\n" + ] + } + ], + "source": [ + "from scipy.stats import expon\n", + "\n", + "scale = 10 \n", + "\n", + "expon_dist = expon(scale=scale)\n", + "\n", + "print(f\"The probability that the next customer will arrive within the next 5 minutes is {expon_dist.cdf(5)*100:.2f}%\")" + ] }, { "cell_type": "markdown", @@ -173,10 +245,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability probability of an employee taking a break is 22.31%\n" + ] + } + ], + "source": [ + "scale = 10 \n", + "\n", + "expon_dist = expon(scale=scale)\n", + "\n", + "print(f\"The probability probability of an employee taking a break is {100- expon_dist.cdf(15)*100:.2f}%\")" + ] }, { "cell_type": "markdown", @@ -196,11 +282,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability that its weight is between 140 and 160 grams is 68.27%\n" + ] + } + ], "source": [ - "#code here" + "from scipy.stats import norm\n", + "mean = 150\n", + "std = 10\n", + "\n", + "norm_dist = norm(loc = mean, scale = std)\n", + "\n", + "print(f\"The probability that its weight is between 140 and 160 grams is {(norm_dist.cdf(160) - norm_dist.cdf(140))*100: .2f}%\")" ] }, { @@ -219,17 +319,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability that the component fails within the first 30 hours is 45.12%\n" + ] + } + ], "source": [ - "#code here" + "scale = 50\n", + "\n", + "expon_dist = expon(scale=scale)\n", + "\n", + "print(f\"The probability that the component fails within the first 30 hours is {expon_dist.cdf(30)*100:.2f}%\")" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -243,9 +362,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.9" + "version": "3.13.9" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }