diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb new file mode 100644 index 0000000..62fc2ea --- /dev/null +++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb @@ -0,0 +1,638 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Intro to Bayesian Statistics Lab\n", + "\n", + "Complete the following set of exercises to solidify your knowledge of Bayesian statistics and Bayesian data analysis." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1. Cookie Problem\n", + "\n", + "Suppose we have two bowls of cookies. Bowl 1 contains 30 vanilla cookies and 10 chocolate cookies. Bowl 2 contains 20 of each. You randomly pick one cookie out of one of the bowls, and it is vanilla. Use Bayes Theorem to calculate the probability that the vanilla cookie you picked came from Bowl 1?" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#p(vainilla|bowl1)\n", + "\n", + "#p_vainilla_bw1 = 30/40\n", + "\n", + "#p_vainilla_bw2 = 20/40\n", + "\n", + "#p_bw1 = 1/2\n", + "#p_bw2 = 1/2\n", + "\n", + "p_bw1_v = (0.75*0.50)/(0.75*0.50+0.5*0.50)\n", + "p_bw1_v" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "What is the probability that it came from Bowl 2?" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.4" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_bw2_v = (0.50*0.50)/(0.75*0.50+0.5*0.50)\n", + "p_bw2_v" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.4" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_bw2_v = 1-p_bw1_v\n", + "p_bw2_v" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "What if the cookie you had picked was chocolate? What are the probabilities that the chocolate cookie came from Bowl 1 and Bowl 2 respectively?" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.3333333333333333 0.6666666666666666\n" + ] + } + ], + "source": [ + "#p_chocolate_bw1 = 10/40\n", + "\n", + "#p_chocolate_bw2 = 20/40\n", + "\n", + "#p_bw1 = 1/2\n", + "#p_bw2 = 1/2\n", + "\n", + "p_bw1_c = (0.25*0.50)/(0.25*0.50+0.5*0.50)\n", + "p_bw2_c = (0.50*0.50)/(0.25*0.50+0.5*0.50)\n", + "\n", + "print(p_bw1_c, p_bw2_c)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2. Candy Problem\n", + "\n", + "Suppose you have two bags of candies:\n", + "\n", + "- In Bag 1, the mix of colors is:\n", + " - Brown - 30%\n", + " - Yellow - 20%\n", + " - Red - 20%\n", + " - Green - 10%\n", + " - Orange - 10%\n", + " - Tan - 10%\n", + " \n", + "- In Bag 2, the mix of colors is:\n", + " - Blue - 24%\n", + " - Green - 20%\n", + " - Orange - 16%\n", + " - Yellow - 14%\n", + " - Red - 13%\n", + " - Brown - 13%\n", + " \n", + "Not knowing which bag is which, you randomly draw one candy from each bag. One is yellow and one is green. What is the probability that the yellow one came from the Bag 1?\n", + "\n", + "*Hint: For the likelihoods, you will need to multiply the probabilities of drawing yellow from one bag and green from the other bag and vice versa.*" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.5882352941176471" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#p(yellow_bag1) = 0.2\n", + "\n", + "#p(green_bag1) = 0.1\n", + "\n", + "#p(yellow_bag2) = 0.14\n", + "\n", + "#p(green_bag2) = 0.2\n", + "\n", + "#p(yellow) = p(yellow_bag1)*p(bag_1)+(p(yellow_bag2)p(bag_2))\n", + "\n", + "p_bag1_yellow = (0.2*0.5)/(0.2*0.5+0.14*0.5)\n", + "p_bag1_yellow" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_bag2_green = (0.2*0.5)/(0.1*0.5+0.2*0.5)\n", + "p_bag2_green" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.39215686274509803" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_yellow_bag1 = p_bag1_yellow * p_bag2_green\n", + "p_yellow_bag1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "What is the probability that the yellow candy came from Bag 2?" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.411764705882353" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_bag2_yellow = (0.14*0.5)/(0.2*0.5+0.14*0.5)\n", + "p_bag2_yellow" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.3333333333333333" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_bag1_green = (0.1*0.5)/(0.1*0.5+0.2*0.5)\n", + "p_bag1_green" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.13725490196078433" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_yellow_bag2 = p_bag2_yellow * p_bag1_green\n", + "p_yellow_bag2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "What are the probabilities that the green one came from Bag 1 and Bag 2 respectively?" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.39215686274509803 0.13725490196078433\n" + ] + } + ], + "source": [ + "p_green_bag2 = p_yellow_bag1\n", + "p_green_bag1 = p_yellow_bag2\n", + "print(p_green_bag2, p_green_bag1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3. Monty Hall Problem\n", + "\n", + "Suppose you are a contestant on the popular game show *Let's Make a Deal*. The host of the show (Monty Hall) presents you with three doors - Door A, Door B, and Door C. He tells you that there is a sports car behind one of them and if you choose the correct one, you win the car!\n", + "\n", + "You select Door A, but then Monty makes things a little more interesting. He opens Door B to reveal that there is no sports car behind it and asks you if you would like to stick with your choice of Door A or switch your choice to Door C. Given this new information, what are the probabilities of you winning the car if you stick with Door A versus if you switch to Door C?" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.3333333333333333" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_doorA_winning = (1/3*1/3)/(1/3*1/3+1/3*1/3+1/3*1/3)\n", + "p_doorA_winning" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_doorC_winning = (2/3*1/3)/(1/3*1/3+1/3*1/3+1/3*1/3)\n", + "p_doorC_winning" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 4. Bayesian Analysis \n", + "\n", + "Suppose you work for a landscaping company, and they want to advertise their service online. They create an ad and sit back waiting for the money to roll in. On the first day, the ad sends 100 visitors to the site and 14 of them sign up for landscaping services. Create a generative model to come up with the posterior distribution and produce a visualization of what the posterior distribution would look like given the observed data." + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "def generative_model(proba_sign):\n", + " sign = np.random.binomial(100, proba_sign)\n", + " return sign" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "n_draws = 100_000\n", + "prior = pd.Series(np.random.uniform(0,1,size=n_draws))" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0 0.547458\n", + "1 0.810353\n", + "2 0.197198\n", + "3 0.828955\n", + "dtype: float64" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prior.head(4)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "sign = list()\n", + "for equipo in prior:\n", + " sign.append(generative_model(equipo))" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "152 0.135124\n", + "253 0.135267\n", + "383 0.170336\n", + "442 0.162218\n", + "533 0.102032\n", + " ... \n", + "99679 0.152464\n", + "99691 0.127766\n", + "99900 0.091326\n", + "99932 0.200202\n", + "99987 0.091736\n", + "Length: 1001, dtype: float64" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "posteriori = prior[list(map(lambda x:x ==14, sign))]\n", + "posteriori" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result"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YOUHCbyMw7gTsj4o+ADwF/PGjfXpPYExjkFhJnnCczT/88BdxJd3dnrRrmdhrn0q04hnovFbeJiHg18Alge2b+6Gz6rhHD1KHkNnFaE3a/GREbzrbv6QWM+yTH+cD3gUtZOlFx+fPmuZ7nnhi+r2lfB7ykZ/prdO9OOvWTN+OqRc+8H+S5J4YH7rvaH0PWodw2AfwGcAx4w0rruNofQ9ah4jbxWyydGH4t8Hjz+/Ost4lJvanrgP+ie9b6b5q2dwHvaqaD7h+h+R5wGJhr2l/ZvIlvA0dO913LjwFq8Wt00/wp4CfN9K+eqe9afay0DkW3iU8ATwKHmsfBF+q7Vh8rrUPRbeKvm/d6CPg68MaVbhPeNkKSCvOKYUkqzBCQpMIMAUkqzBCQpMIMAUkqzBCQpMIMAUkq7P8BaH/X8pZhrawAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "posteriori.hist()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Produce a set of descriptive statistics for the posterior distribution." + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "count 1001.000000\n", + "mean 0.145773\n", + "std 0.034879\n", + "min 0.060491\n", + "25% 0.121485\n", + "50% 0.142566\n", + "75% 0.166545\n", + "max 0.289293\n", + "dtype: float64" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "posteriori.describe()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "What is the 90% credible interval range?" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(0.09173594908655702,0.21063461892125546)\n" + ] + } + ], + "source": [ + "# Intervalo de confianza el 90% centrado\n", + "print(f'({posteriori.quantile(0.05)},{posteriori.quantile(0.95)})')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "What is the Maximum Likelihood Estimate?" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.14577290668248988" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "posteriori.mean()" + ] + } + ], + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 95bfcb9..62fc2ea 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -31,10 +31,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "0.6" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#p(vainilla|bowl1)\n", + "\n", + "#p_vainilla_bw1 = 30/40\n", + "\n", + "#p_vainilla_bw2 = 20/40\n", + "\n", + "#p_bw1 = 1/2\n", + "#p_bw2 = 1/2\n", + "\n", + "p_bw1_v = (0.75*0.50)/(0.75*0.50+0.5*0.50)\n", + "p_bw1_v" + ] }, { "cell_type": "markdown", @@ -45,10 +68,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "0.4" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_bw2_v = (0.50*0.50)/(0.75*0.50+0.5*0.50)\n", + "p_bw2_v" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.4" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_bw2_v = 1-p_bw1_v\n", + "p_bw2_v" + ] }, { "cell_type": "markdown", @@ -59,10 +117,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.3333333333333333 0.6666666666666666\n" + ] + } + ], + "source": [ + "#p_chocolate_bw1 = 10/40\n", + "\n", + "#p_chocolate_bw2 = 20/40\n", + "\n", + "#p_bw1 = 1/2\n", + "#p_bw2 = 1/2\n", + "\n", + "p_bw1_c = (0.25*0.50)/(0.25*0.50+0.5*0.50)\n", + "p_bw2_c = (0.50*0.50)/(0.25*0.50+0.5*0.50)\n", + "\n", + "print(p_bw1_c, p_bw2_c)" + ] }, { "cell_type": "markdown", @@ -95,10 +173,76 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "0.5882352941176471" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#p(yellow_bag1) = 0.2\n", + "\n", + "#p(green_bag1) = 0.1\n", + "\n", + "#p(yellow_bag2) = 0.14\n", + "\n", + "#p(green_bag2) = 0.2\n", + "\n", + "#p(yellow) = p(yellow_bag1)*p(bag_1)+(p(yellow_bag2)p(bag_2))\n", + "\n", + "p_bag1_yellow = (0.2*0.5)/(0.2*0.5+0.14*0.5)\n", + "p_bag1_yellow" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_bag2_green = (0.2*0.5)/(0.1*0.5+0.2*0.5)\n", + "p_bag2_green" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.39215686274509803" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_yellow_bag1 = p_bag1_yellow * p_bag2_green\n", + "p_yellow_bag1" + ] }, { "cell_type": "markdown", @@ -109,10 +253,66 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "0.411764705882353" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_bag2_yellow = (0.14*0.5)/(0.2*0.5+0.14*0.5)\n", + "p_bag2_yellow" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.3333333333333333" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_bag1_green = (0.1*0.5)/(0.1*0.5+0.2*0.5)\n", + "p_bag1_green" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.13725490196078433" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_yellow_bag2 = p_bag2_yellow * p_bag1_green\n", + "p_yellow_bag2" + ] }, { "cell_type": "markdown", @@ -123,10 +323,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.39215686274509803 0.13725490196078433\n" + ] + } + ], + "source": [ + "p_green_bag2 = p_yellow_bag1\n", + "p_green_bag1 = p_yellow_bag2\n", + "print(p_green_bag2, p_green_bag1)" + ] }, { "cell_type": "markdown", @@ -141,10 +353,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "0.3333333333333333" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_doorA_winning = (1/3*1/3)/(1/3*1/3+1/3*1/3+1/3*1/3)\n", + "p_doorA_winning" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p_doorC_winning = (2/3*1/3)/(1/3*1/3+1/3*1/3+1/3*1/3)\n", + "p_doorC_winning" + ] }, { "cell_type": "markdown", @@ -157,10 +404,127 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "def generative_model(proba_sign):\n", + " sign = np.random.binomial(100, proba_sign)\n", + " return sign" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "n_draws = 100_000\n", + "prior = pd.Series(np.random.uniform(0,1,size=n_draws))" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0 0.547458\n", + "1 0.810353\n", + "2 0.197198\n", + "3 0.828955\n", + "dtype: float64" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prior.head(4)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "sign = list()\n", + "for equipo in prior:\n", + " sign.append(generative_model(equipo))" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "152 0.135124\n", + "253 0.135267\n", + "383 0.170336\n", + "442 0.162218\n", + "533 0.102032\n", + " ... \n", + "99679 0.152464\n", + "99691 0.127766\n", + "99900 0.091326\n", + "99932 0.200202\n", + "99987 0.091736\n", + "Length: 1001, dtype: float64" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "posteriori = prior[list(map(lambda x:x ==14, sign))]\n", + "posteriori" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYEAAAD4CAYAAAAKA1qZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAQYUlEQVR4nO3df4wcd3nH8ffTBKLIphBkcnUdVxda90eCIYVrigiqNqJt0kSWQSqVUYRikcogBQlUI9Whf4CELOWPBqSqUPUgiFRQXKsQYRFom0asIsSPxEEGx4lTDLkSx5EtIBA2QmkvffrHjrlNOGfXt7/u/Lxf0upmvzvfme8+nr2PZ2ZnLjITSVJNvzLtAUiSpscQkKTCDAFJKswQkKTCDAFJKuz8aQ8AYMOGDTk7O8vTTz/NunXrpj2cqbMOS6xFl3VYYi26nn76aY4ePfrDzHzFMMtZFSEwOzvLwYMHabfbtFqtaQ9n6qzDEmvRZR2WWIuudrvN1Vdf/d/DLsfDQZJUmCEgSYUZApJUmCEgSYUZApJUmCEgSYUZApJUmCEgSYUZApJU2Kq4Ylhrx+yeuya6vt1bF9m55y4Wbr1+ouuVqnBPQJIKMwQkqTBDQJIKMwQkqTBDQJIKMwQkqTBDQJIK6xsCEbE5Ir4SEQ9HxJGIeE/T/sGIeDwiDjWP63r63BIRxyLikYi4ZpxvQJK0coNcLLYI7M7Mb0XES4AHIuLu5rWPZObf9s4cEZcBO4DLgV8H/jMifjsznx3lwCVJw+u7J5CZT2Tmt5rpnwEPA5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Yk9gkFtIbAf+Kbu+AbwsIjZOYGyT1rcWmXkqM+8H/vds+64hw9ThXDNILb6WmU82T79B97qbgfquIcPU4VwzSC062fzWB9axdDHuWW8TkwiBTcBjPc+PN22DzpPAf0TEA82tJtayQWoxjr6rzbDvpfI2cRPdveaV9F3NhqkDFNwmIuItEXEUuAt4x9n07TWJPyrT9xYSfea5KjNPRMTFwN0RcTQz7x3pCCdnkFqMo+9qM+x7KblNRMTVdH/5nT7+W3KbWKYOUHCbyMw7gTsj4o+ADwF/PGjfXpPYExjkFhJnnCczT/88BdxJd3dnrRrmdhrn0q04hnovFbeJiHg18Alge2b+6Gz6rhHD1KHkNnFaE3a/GREbzrbv6QWM+yTH+cD3gUtZOlFx+fPmuZ7nnhi+r2lfB7ykZ/prdO9OOvWTN+OqRc+8H+S5J4YH7rvaH0PWodw2AfwGcAx4w0rruNofQ9ah4jbxWyydGH4t8Hjz+/Ost4lJvanrgP+ie9b6b5q2dwHvaqaD7h+h+R5wGJhr2l/ZvIlvA0dO913LjwFq8Wt00/wp4CfN9K+eqe9afay0DkW3iU8ATwKHmsfBF+q7Vh8rrUPRbeKvm/d6CPg68MaVbhPeNkKSCvOKYUkqzBCQpMIMAUkqzBCQpMIMAUkqzBCQpMIMAUkq7P8BaH/X8pZhrawAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "posteriori.hist()" + ] }, { "cell_type": "markdown", @@ -171,10 +535,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "count 1001.000000\n", + "mean 0.145773\n", + "std 0.034879\n", + "min 0.060491\n", + "25% 0.121485\n", + "50% 0.142566\n", + "75% 0.166545\n", + "max 0.289293\n", + "dtype: float64" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "posteriori.describe()" + ] }, { "cell_type": "markdown", @@ -185,10 +570,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(0.09173594908655702,0.21063461892125546)\n" + ] + } + ], + "source": [ + "# Intervalo de confianza el 90% centrado\n", + "print(f'({posteriori.quantile(0.05)},{posteriori.quantile(0.95)})')" + ] }, { "cell_type": "markdown", @@ -199,10 +595,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "0.14577290668248988" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "posteriori.mean()" + ] } ], "metadata": { @@ -221,7 +630,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4,