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

Solved Lab Benjamin Mancera #212

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
220 changes: 194 additions & 26 deletions lab-intro-probability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"La probabilidad de que falten 10 pasajeros o más es: 0.1853\n"
]
}
],
"source": [
"#code here"
"import scipy.stats as stats\n",
"\n",
"# Número de boletos vendidos\n",
"n = 460\n",
"# Probabilidad de que un pasajero no se presente\n",
"p = 0.03\n",
"# Número de pasajeros que se presentan\n",
"k = 450\n",
"\n",
"# Calculamos la probabilidad de que 10 o más pasajeros no se presenten\n",
"prob = 1 - stats.binom.cdf(k - 1, n, 1 - p)\n",
"\n",
"print(f\"La probabilidad de que falten 10 pasajeros o más es: {prob:.4f}\")"
]
},
{
Expand Down Expand Up @@ -72,11 +92,32 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 17,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability that the representative needs at least three attempts is: 0.4900\n",
"The probability that the representative needs exactly three attempts is: 0.1470\n"
]
}
],
"source": [
"#code here"
"# Probabilidad de éxito en cada intento\n",
"p = 0.3\n",
"# Número de intentos\n",
"k = 3\n",
"\n",
"# Calculamos la probabilidad de que se necesiten al menos 3 intentos (fallar en los primeros 2 intentos)\n",
"prob_at_least_3_attempts = (1 - p) ** (k - 1)\n",
"\n",
"# Calculamos la probabilidad de que se necesiten exactamente 3 intentos (fallar en los primeros 2 intentos y luego tener éxito)\n",
"prob_exactly_3_attempts = (1 - p) ** (k - 1) * p\n",
"\n",
"print(f\"The probability that the representative needs at least three attempts is: {prob_at_least_3_attempts:.4f}\")\n",
"print(f\"The probability that the representative needs exactly three attempts is: {prob_exactly_3_attempts:.4f}\")"
]
},
{
Expand Down Expand Up @@ -107,11 +148,29 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability of the website server being overwhelmed is: 0.0129\n"
]
}
],
"source": [
"#code here"
"import scipy.stats as stats\n",
"\n",
"# Tasa promedio de visitas por hora\n",
"lambda_ = 500\n",
"# Capacidad máxima del servidor\n",
"max_visits = 550\n",
"\n",
"# Calculamos la probabilidad de que el número de visitas sea mayor que 550\n",
"prob = 1 - stats.poisson.cdf(max_visits, lambda_)\n",
"\n",
"print(f\"The probability of the website server being overwhelmed is: {prob:.4f}\")"
]
},
{
Expand All @@ -123,11 +182,38 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability of the website server being overwhelmed at some point during a day is: 0.2677\n"
]
}
],
"source": [
"#code here"
"import scipy.stats as stats\n",
"\n",
"# Tasa promedio de visitas por hora\n",
"lambda_ = 500\n",
"# Capacidad máxima del servidor\n",
"max_visits = 550\n",
"\n",
"# Calculamos la probabilidad de que el número de visitas sea mayor que 550 en una hora\n",
"prob_overwhelmed_per_hour = 1 - stats.poisson.cdf(max_visits, lambda_)\n",
"\n",
"# Calculamos la probabilidad de que el servidor no se vea abrumado en una hora\n",
"prob_not_overwhelmed_per_hour = 1 - prob_overwhelmed_per_hour\n",
"\n",
"# Calculamos la probabilidad de que el servidor no se vea abrumado en ninguna de las 24 horas\n",
"prob_not_overwhelmed_per_day = prob_not_overwhelmed_per_hour ** 24\n",
"\n",
"# Calculamos la probabilidad de que el servidor se vea abrumado al menos una vez en 24 horas\n",
"prob_overwhelmed_per_day = 1 - prob_not_overwhelmed_per_day\n",
"\n",
"print(f\"The probability of the website server being overwhelmed at some point during a day is: {prob_overwhelmed_per_day:.4f}\")"
]
},
{
Expand Down Expand Up @@ -157,10 +243,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability that the next customer will arrive within the next 5 minutes is: 0.3935\n"
]
}
],
"source": [
"import scipy.stats as stats\n",
"\n",
"# Tasa promedio de llegadas (por minuto)\n",
"lambda_ = 1 / 10\n",
"# Tiempo en minutos\n",
"t = 5\n",
"\n",
"# Calculamos la probabilidad de que el próximo cliente llegue dentro de los próximos 5 minutos\n",
"prob = stats.expon.cdf(t, scale=1/lambda_)\n",
"\n",
"print(f\"The probability that the next customer will arrive within the next 5 minutes is: {prob:.4f}\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -173,10 +279,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability that an employee can take a break is: 0.2231\n"
]
}
],
"source": [
"import scipy.stats as stats\n",
"\n",
"# Tasa promedio de llegadas (por minuto)\n",
"lambda_ = 1 / 10\n",
"# Tiempo en minutos\n",
"t = 15\n",
"\n",
"# Calculamos la probabilidad de que no haya clientes durante 15 minutos\n",
"prob = stats.expon.cdf(t, scale=1/lambda_)\n",
"\n",
"# La probabilidad de que no haya clientes durante 15 minutos es 1 menos la probabilidad acumulada\n",
"prob_no_customers = 1 - prob\n",
"\n",
"print(f\"The probability that an employee can take a break is: {prob_no_customers:.4f}\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -196,11 +325,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability that the bird's weight is between 140 and 160 grams is: 0.6827\n"
]
}
],
"source": [
"#code here"
"import scipy.stats as stats\n",
"\n",
"# Parámetros de la distribución normal\n",
"mu = 150\n",
"sigma = 10\n",
"\n",
"# Pesos entre los que queremos calcular la probabilidad\n",
"lower_bound = 140\n",
"upper_bound = 160\n",
"\n",
"# Calculamos la probabilidad de que el peso esté entre 140 y 160 gramos\n",
"prob = stats.norm.cdf(upper_bound, mu, sigma) - stats.norm.cdf(lower_bound, mu, sigma)\n",
"\n",
"print(f\"The probability that the bird's weight is between 140 and 160 grams is: {prob:.4f}\")"
]
},
{
Expand All @@ -219,17 +369,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability that the component fails within the first 30 hours is: 0.4512\n"
]
}
],
"source": [
"#code here"
"import scipy.stats as stats\n",
"\n",
"# Tasa promedio de fallos (por hora)\n",
"lambda_ = 1 / 50\n",
"# Tiempo en horas\n",
"t = 30\n",
"\n",
"# Calculamos la probabilidad de que el componente falle dentro de las primeras 30 horas\n",
"prob = stats.expon.cdf(t, scale=1/lambda_)\n",
"\n",
"print(f\"The probability that the component fails within the first 30 hours is: {prob:.4f}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -243,7 +411,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down