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
247 changes: 228 additions & 19 deletions lab-intro-probability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"#code here"
"from scipy.stats import binom"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.884477246621543\n"
]
}
],
"source": [
"n = 460 # tickets sold\n",
"p = 0.03 # probability of missing flight\n",
"\n",
"prob = 1 - binom.cdf(9, n, p)\n",
"\n",
"print(prob)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"About 88.1% chance that there are enough seats for everyone."
]
},
{
Expand Down Expand Up @@ -72,11 +101,30 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.48999999999999994\n"
]
}
],
"source": [
"#code here"
"p = 0.3\n",
"\n",
"prob = (1 - p) ** 2\n",
"\n",
"print(prob)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There is a 49% probability the representative needs three or more attempts."
]
},
{
Expand Down Expand Up @@ -107,11 +155,40 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"#code here"
"from scipy.stats import poisson"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.01289822084039205\n"
]
}
],
"source": [
"lam = 500\n",
"\n",
"# Probability visits exceed server capacity\n",
"prob = 1 - poisson.cdf(550, lam)\n",
"\n",
"print(prob)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"About 1.2% chance the server is overwhelmed."
]
},
{
Expand All @@ -125,9 +202,32 @@
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.2677043869515715\n"
]
}
],
"source": [
"#code here"
"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": {},
"source": [
"27% probability of happening at least once during a day."
]
},
{
Expand Down Expand Up @@ -157,10 +257,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": []
"source": [
"from scipy.stats import expon"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.3934693402873666\n"
]
}
],
"source": [
"rate = 1/10\n",
"\n",
"prob = expon.cdf(5, scale=1/rate)\n",
"\n",
"print(prob)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There is about a 39% chance the next customer arrives within 5 minutes."
]
},
{
"cell_type": "markdown",
Expand All @@ -173,10 +303,41 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": []
"source": [
"import math"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.22313016014842982\n"
]
}
],
"source": [
"lam = 0.1\n",
"t = 15\n",
"\n",
"prob = math.exp(-lam * t)\n",
"\n",
"print(prob)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There's a 22% chance of an employee taking a break."
]
},
{
"cell_type": "markdown",
Expand All @@ -196,11 +357,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"#code here"
"from scipy.stats import norm"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.6826894921370859\n"
]
}
],
"source": [
"mu = 150\n",
"sigma = 10\n",
"\n",
"prob = norm.cdf(160, mu, sigma) - norm.cdf(140, mu, sigma)\n",
"\n",
"print(prob)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"68% of bird weight being between 140 and 160 grams."
]
},
{
Expand All @@ -219,11 +409,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.4511883639059735\n"
]
}
],
"source": [
"mean = 50\n",
"\n",
"prob = expon.cdf(30, scale=mean)\n",
"\n",
"print(prob)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"#code here"
"There is about a 45.1% probability that the component fails within the first 30 hours."
]
}
],
Expand All @@ -243,7 +452,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.13.11"
}
},
"nbformat": 4,
Expand Down