From 4957482e67034cacf00382c047edfff8b6a22540 Mon Sep 17 00:00:00 2001 From: Dee-M123 Date: Wed, 4 Mar 2026 15:29:54 +0100 Subject: [PATCH] Created using Colab --- lab_intro_probability.ipynb | 470 ++++++++++++++++++++++++++++++++++++ 1 file changed, 470 insertions(+) create mode 100644 lab_intro_probability.ipynb diff --git a/lab_intro_probability.ipynb b/lab_intro_probability.ipynb new file mode 100644 index 0000000..9809f5f --- /dev/null +++ b/lab_intro_probability.ipynb @@ -0,0 +1,470 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "zxbPidmFMIZ7" + }, + "source": [ + "# Lab | Intro to Probability" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "D6Fh02oPMIZ9" + }, + "source": [ + "**Objective**\n", + "\n", + "Welcome to this Intro to Probability lab, where we explore decision-making scenarios through the lens of probability and strategic analysis. In the business world, making informed decisions is crucial, especially when faced with uncertainties. This lab focuses on scenarios where probabilistic outcomes play a significant role in shaping strategies and outcomes. Students will engage in exercises that require assessing and choosing optimal paths based on data-driven insights. The goal is to enhance your skills by applying probability concepts to solve real-world problems." + ] + }, + { + "cell_type": "code", + "source": [ + "import numpy as np\n", + "import pandas as pd\n", + "from scipy import stats\n", + "from scipy.stats import binom" + ], + "metadata": { + "id": "JwIgDtzQMPbD" + }, + "execution_count": 3, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "L_tycIZzMIZ9" + }, + "source": [ + "**Challenge 1**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SMiq5XrjMIZ9" + }, + "source": [ + "#### Ironhack Airlines\n", + "\n", + "Often Airlines sell more tickets than they have seats available, this is called overbooking. Consider the following:\n", + "- A plane has 450 seats.\n", + "- Based on historical data we conclude that each individual passenger has a 3% chance of missing it's flight.\n", + "\n", + "If the Ironhack Airlines routinely sells 460 tickets, what is the chance that they have a seats for all passenger?" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "7EvLHzE-MIZ-", + "outputId": "c525040d-6545-457b-e846-ed1914c915c1" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "0.8844772466215431\n" + ] + } + ], + "source": [ + "\n", + "n = 460 # tickets sold\n", + "\n", + "p = 0.97 # probability passenger shows up\n", + "\n", + "seats = 450\n", + "\n", + "# probability that 450 or fewer passengers show up\n", + "prob = binom.cdf(seats, n, p)\n", + "\n", + "print(prob)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "enZiNh1-MIZ-" + }, + "source": [ + "**Challenge 2**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FzQdhufGMIZ-" + }, + "source": [ + "#### Ironhack Call Center" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Xdmof59PMIZ-" + }, + "source": [ + "Suppose a customer service representative at a call center is handling customer complaints. Consider the following:\n", + "- The probability of successfully resolving a customer complaint on the first attempt is 0.3.\n", + "\n", + "\n", + "What is the probability that the representative needs to make at least three attempts before successfully resolving a customer complaint?" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "QDDoPF-QMIZ-", + "outputId": "3faefe58-34c4-418a-9559-8e258b82f49c" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "0.48999999999999994\n" + ] + } + ], + "source": [ + "p = 0.3\n", + "\n", + "success = (1 - p)**2\n", + "\n", + "print(success)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "oFMH3VdQMIZ_" + }, + "source": [ + "**Challenge 3**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "MoErRC08MIZ_" + }, + "source": [ + "#### Ironhack Website" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "smFLYerKMIZ_" + }, + "source": [ + "Consider a scenario related to Ironhack website traffic. Where:\n", + "- our website takes on average 500 visits per hour.\n", + "- the website's server is designed to handle up to 550 vists per hour.\n", + "\n", + "\n", + "What is the probability of the website server being overwhelmed?" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "AwHh7uKIMIZ_", + "outputId": "d4b74587-148b-4646-9416-0f77d8edfb2d" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "0.01289822084039205\n" + ] + } + ], + "source": [ + "from scipy.stats import poisson\n", + "# average visits\n", + "lam = 500\n", + "\n", + "# probability server is overwhelmed (more than 550 visits)\n", + "prob = 1 - poisson.cdf(550, lam)\n", + "\n", + "print(prob)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "RP8rjMd1MIZ_" + }, + "source": [ + "What is the probability of being overwhelmed at some point during a day? (consider 24hours)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "Ps44DP1hMIZ_", + "outputId": "7847e541-daf0-46b1-8467-a1bb6b7410ae" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "0.2677043869515715\n" + ] + } + ], + "source": [ + "lam = 500\n", + "\n", + "# probability server is overwhelmed in one hour\n", + "p_hour = 1 - poisson.cdf(550, lam)\n", + "\n", + "# probability it happens at least once in 24 hours\n", + "p_day = 1 - (1 - p_hour)**24\n", + "\n", + "print(p_day)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "yGimt0sCMIZ_" + }, + "source": [ + "**Challenge 4**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FRNAviW6MIZ_" + }, + "source": [ + "#### Ironhack Helpdesk" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cxitUiLeMIZ_" + }, + "source": [ + "Consider a scenario related to the time between arrivals of customers at a service desk.\n", + "\n", + "On average, a customers arrives every 10minutes.\n", + "\n", + "What is the probability that the next customer will arrive within the next 5 minutes?" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "EuxwrWOTMIZ_", + "outputId": "bdde34fc-7185-48b5-bf8c-42b876336b21" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "0.3934693402873666\n" + ] + } + ], + "source": [ + "from scipy.stats import expon\n", + "scale = 10\n", + "\n", + "# probability next customer arrives within 5 minutes\n", + "prob = expon.cdf(5, scale=scale)\n", + "\n", + "print(prob)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3OTOkT_9MIZ_" + }, + "source": [ + "If there is no customer for 15minutes, employees can that a 5minutes break.\n", + "\n", + "What is the probability an employee taking a break?" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "doGSchFZMIZ_", + "outputId": "a0bd2b75-b524-4088-ed70-07ef7cc91c37" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "0.2231301601484298\n" + ] + } + ], + "source": [ + "scale = 10\n", + "\n", + "# probability no customer arrives for 15 minutes\n", + "prob = 1 - expon.cdf(15, scale=10)\n", + "\n", + "print(prob)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FuOBQNp0MIaA" + }, + "source": [ + "**Challenge 5**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "oLMpSiT-MIaA" + }, + "source": [ + "The weights of a certain species of birds follow a normal distribution with a mean weight of 150 grams and a standard deviation of 10 grams.\n", + "\n", + "- If we randomly select a bird, what is the probability that its weight is between 140 and 160 grams?" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "LVZwEGHFMIaA", + "outputId": "a3d146c5-5101-43ab-cba8-fbc9fbd3aed7" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "0.6826894921370859\n" + ] + } + ], + "source": [ + "from scipy.stats import norm\n", + "prob = norm.cdf(160, loc=150, scale=10) - norm.cdf(140, loc=150, scale=10)\n", + "\n", + "print(prob)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "-mqciXs6MIaA" + }, + "source": [ + "**Challenge 6**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "UF1UvoYnMIaA" + }, + "source": [ + "If the lifetime (in hours) of a certain electronic component follows an exponential distribution with a mean lifetime of 50 hours, what is the probability that the component fails within the first 30 hours?" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "BooFnEKSMIaA", + "outputId": "47023e1b-e97c-435c-ce24-2bb30271f6ae" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "0.4511883639059736\n" + ] + } + ], + "source": [ + "scale = 50\n", + "\n", + "# probability component fails within 30 hours\n", + "prob = expon.cdf(30, scale=scale)\n", + "\n", + "print(prob)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.9" + }, + "colab": { + "provenance": [] + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file