Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab probability complete #164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
382 changes: 382 additions & 0 deletions .ipynb_checkpoints/lab-intro-probability-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,382 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lab | Intro to Probability"
]
},
{
"cell_type": "markdown",
"metadata": {},
"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": "markdown",
"metadata": {},
"source": [
"**Challenge 1**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"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": 25,
"metadata": {},
"outputs": [],
"source": [
"from scipy.stats import geom, binom, norm, expon, poisson\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.8844772466215431"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Binomial\n",
"# chance of 450 show ups\n",
"# with 460 tickets\n",
"# 97% of passengers show\n",
"\n",
"n=460\n",
"p=0.97\n",
"binom_dist=binom(n,p)\n",
"binom_dist.cdf(450)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Challenge 2**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Ironhack Call Center "
]
},
{
"cell_type": "markdown",
"metadata": {},
"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": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.49"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# geometric (trials required to achieve first success)\n",
"# the representative needs to fail on 1st & 2d attemps\n",
"# the chance of failing is 0.7\n",
"# the chance of failing on the 1st AND 2d attempt is 0.7*0.7 = 0.49\n",
"\n",
"p=0.3\n",
"geom_dist=geom(p)\n",
"1-geom_dist.cdf(2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Challenge 3**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Ironhack Website"
]
},
{
"cell_type": "markdown",
"metadata": {},
"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": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.01289822084039205"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#poisson: proba of a given number of events occur in a fixed interval\n",
"# mu = average rate of events = 500\n",
"# proba that >550 visits per hour\n",
"\n",
"mu=500\n",
"poisson_d=poisson(mu)\n",
"1-poisson_d.cdf(550)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What is the probability of being overwhelmed at some point during a day? (consider 24hours)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"#code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Challenge 4**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Ironhack Helpdesk"
]
},
{
"cell_type": "markdown",
"metadata": {},
"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": 45,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.3934693402873666"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#exponential\n",
"#the parameter represents the rate of events occuring per unit of time\n",
"mean_time=10\n",
"lambda_value = 1/mean_time\n",
"\n",
"expo_dist = expon(scale = 1/lambda_value)\n",
"\n",
"expo_dist.cdf(5)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"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": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.2231301601484298"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1-expo_dist.cdf(15)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Challenge 5**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"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": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.6826894921370859"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#normal distribution : natural symetry and tendancy to cluster around an average\n",
"mean = 150\n",
"std = 10\n",
"\n",
"norm_dist = norm(loc = mean, scale = std)\n",
"norm_dist.cdf(160) - norm_dist.cdf(140)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Challenge 6**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"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": 53,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.4511883639059735"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#exponantial distribution, time between independnat events\n",
"mean_time=50\n",
"lambda_value = 1/mean_time\n",
"\n",
"expo_dist = expon(scale = 1/lambda_value)\n",
"\n",
"expo_dist.cdf(30)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading