Skip to content
Open
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
173 changes: 146 additions & 27 deletions lab-intro-probability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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}%\")"
]
},
{
Expand Down Expand Up @@ -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%\")"
]
},
{
Expand Down Expand Up @@ -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}\")"
]
},
{
Expand All @@ -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}%\")"
]
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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}%\")"
]
},
{
Expand All @@ -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"
},
Expand All @@ -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
}