{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Random Numbers and Probability\n",
"> In this chapter, you'll learn how to generate random samples and measure chance using probability. You'll work with real-world sales data to calculate the probability of a salesperson being successful. Finally, you’ll use the binomial distribution to model events with binary outcomes. This is the Summary of lecture \"Introduction to Statistics in Python\", via datacamp.\n",
"\n",
"- toc: true \n",
"- badges: true\n",
"- comments: true\n",
"- author: Chanseok Kang\n",
"- categories: [Python, Datacamp, Statistics]\n",
"- image: images/uniform_dist_wait.png "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.rcParams['figure.figsize'] = (10, 8)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## What are the chances?\n",
"- Measuring chance\n",
"\n",
"What's the probability of an event?\n",
"$$ P(\\text{event}) = \\frac{\\text{# ways event can happen}}{\\text{total # of possible outcomes}} $$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Calculating probabilities\n",
"You're in charge of the sales team, and it's time for performance reviews, starting with Amir. As part of the review, you want to randomly select a few of the deals that he's worked on over the past year so that you can look at them more deeply. Before you start selecting deals, you'll first figure out what the chances are of selecting certain deals.\n",
"\n",
"Recall that the probability of an event can be calculated by\n",
"\n",
"$$ P(\\text{event}) = \\frac{\\text{# ways event can happen}}{\\text{total # of possible outcomes}} $$"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" product \n",
" client \n",
" status \n",
" amount \n",
" num_users \n",
" \n",
" \n",
" \n",
" \n",
" 1 \n",
" Product F \n",
" Current \n",
" Won \n",
" 7389.52 \n",
" 19 \n",
" \n",
" \n",
" 2 \n",
" Product C \n",
" New \n",
" Won \n",
" 4493.01 \n",
" 43 \n",
" \n",
" \n",
" 3 \n",
" Product B \n",
" New \n",
" Won \n",
" 5738.09 \n",
" 87 \n",
" \n",
" \n",
" 4 \n",
" Product I \n",
" Current \n",
" Won \n",
" 2591.24 \n",
" 83 \n",
" \n",
" \n",
" 5 \n",
" Product E \n",
" Current \n",
" Won \n",
" 6622.97 \n",
" 17 \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" product client status amount num_users\n",
"1 Product F Current Won 7389.52 19\n",
"2 Product C New Won 4493.01 43\n",
"3 Product B New Won 5738.09 87\n",
"4 Product I Current Won 2591.24 83\n",
"5 Product E Current Won 6622.97 17"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"amir_deals = pd.read_csv('./dataset/amir_deals.csv', index_col=0)\n",
"amir_deals.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Product B 62\n",
"Product D 40\n",
"Product A 23\n",
"Product C 15\n",
"Product F 11\n",
"Product H 8\n",
"Product I 7\n",
"Product E 5\n",
"Product N 3\n",
"Product G 2\n",
"Product J 2\n",
"Name: product, dtype: int64\n",
"Product B 0.348315\n",
"Product D 0.224719\n",
"Product A 0.129213\n",
"Product C 0.084270\n",
"Product F 0.061798\n",
"Product H 0.044944\n",
"Product I 0.039326\n",
"Product E 0.028090\n",
"Product N 0.016854\n",
"Product G 0.011236\n",
"Product J 0.011236\n",
"Name: product, dtype: float64\n"
]
}
],
"source": [
"# Count the deals for each product\n",
"counts = amir_deals['product'].value_counts()\n",
"print(counts)\n",
"\n",
"# Calculate probability of picking a deal with each product\n",
"probs = counts / len(amir_deals['product'])\n",
"print(probs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Sampling deals\n",
"In the previous exercise, you counted the deals Amir worked on. Now it's time to randomly pick five deals so that you can reach out to each customer and ask if they were satisfied with the service they received. You'll try doing this both with and without replacement.\n",
"\n",
"Additionally, you want to make sure this is done randomly and that it can be reproduced in case you get asked how you chose the deals, so you'll need to set the random seed before sampling from the deals."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" product client status amount num_users\n",
"128 Product B Current Won 2070.25 7\n",
"149 Product D Current Won 3485.48 52\n",
"78 Product B Current Won 6252.30 27\n",
"105 Product D Current Won 4110.98 39\n",
"167 Product C New Lost 3779.86 11\n"
]
}
],
"source": [
"# Set random seed\n",
"np.random.seed(24)\n",
"\n",
"# Sample 5 deals without replacement\n",
"sample_without_replacement = amir_deals.sample(5, replace=False)\n",
"print(sample_without_replacement)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" product client status amount num_users\n",
"163 Product D Current Won 6755.66 59\n",
"132 Product B Current Won 6872.29 25\n",
"88 Product C Current Won 3579.63 3\n",
"146 Product A Current Won 4682.94 63\n",
"146 Product A Current Won 4682.94 63\n"
]
}
],
"source": [
"# Set random seed\n",
"np.random.seed(24)\n",
"\n",
"# Sample 5 deals with replacement\n",
"sample_with_replacement = amir_deals.sample(5, replace=True)\n",
"print(sample_with_replacement)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Discrete distributions\n",
"- Probability distribution\n",
" - Describes the probability of each possible outcome in a scenario\n",
" - **Expected value**: mean of a probability distribution\n",
"- Law of Large Numbers (LLN)\n",
" - As the size of your sample increases, the sample mean will approach the expected value."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Creating a probability distribution\n",
"A new restaurant opened a few months ago, and the restaurant's management wants to optimize its seating space based on the size of the groups that come most often. On one night, there are 10 groups of people waiting to be seated at the restaurant, but instead of being called in the order they arrived, they will be called randomly. In this exercise, you'll investigate the probability of groups of different sizes getting picked first. \n",
"\n",
"Remember that expected value can be calculated by multiplying each possible outcome with its corresponding probability and taking the sum."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" group_id \n",
" group_size \n",
" \n",
" \n",
" \n",
" \n",
" 0 \n",
" A \n",
" 2 \n",
" \n",
" \n",
" 1 \n",
" B \n",
" 4 \n",
" \n",
" \n",
" 2 \n",
" C \n",
" 6 \n",
" \n",
" \n",
" 3 \n",
" D \n",
" 2 \n",
" \n",
" \n",
" 4 \n",
" E \n",
" 2 \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" group_id group_size\n",
"0 A 2\n",
"1 B 4\n",
"2 C 6\n",
"3 D 2\n",
"4 E 2"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"restaurant_groups = pd.read_csv('./dataset/restaurant_groups.csv')\n",
"restaurant_groups.head()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkkAAAHSCAYAAAD4yV8pAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAVI0lEQVR4nO3df4zkd33f8de7d05xbsGWarqhMe05aoSUxE3BK7fIKtqFKHUAwR+lqiOFBJTo1B9xqeQqIpX6I5WqqlIchVpVKgqJaet0EzlQUyuQuCLbBKl2umecGDCREKLCgvggbg3rWqBLPv3jxuRY3nc7l9zsjOf7eEgr78587+b91lc79/TM7GyNMQIAwDf6M8seAABgFYkkAICGSAIAaIgkAICGSAIAaIgkAIDGyUX8pTfccMM4ffr0Iv7qr3v22Wdz6tSphd7Gqpry7sm095/y7sm097f7NHdPpr3/ce1+9uzZL40xXnr48oVE0unTp7O/v7+Iv/rr9vb2sr29vdDbWFVT3j2Z9v5T3j2Z9v523172GEsz5f2Pa/eq+t/d5Z5uAwBoiCQAgIZIAgBoiCQAgIZIAgBoiCQAgIZIAgBoi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HreV5n2f3dT3vSVJVp2Y/pJLZUy3fn+Tjhw5by/v7ZL791/U+f4zx+0k+V1WvmF30uiSHf0hpKed+1X+67bYkb03y+Oz1GUnyT5L8xSQZY/z7XHgn8Ncn+XSS/5fk7UuYcxHm2f0tSf5eVZ1P8lySO9bhH4uZlyV5X1WdyIU7gl8eYzxYVf8yyf4Y44O5EJH/qao+nQuPJNyxvHGvqnl2/4dV9aZc+CnIp5O8bWnTHoOJnPfWhM77ZpIPzBrgZJJfHGN8uKr+brL29/fJfPuv833+nUnum/1k22eSvH0Vzr133AYAaKz0020AAMsikgAAGiIJAKAhkgAAGiIJAKAhkgAAGiIJAKAhkgAAGv8fkWXRn0Sqv6oAAAAASUVORK5CYII=\n",
"text/plain": [
""
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Create a histogram of restaurant_groups and show plot\n",
"restaurant_groups['group_size'].hist(bins=[2, 3, 4, 5, 6]);"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" group_size prob\n",
"0 0 0.2\n",
"1 1 0.4\n",
"2 2 0.6\n",
"3 3 0.2\n",
"4 4 0.2\n",
"5 5 0.2\n",
"6 6 0.3\n",
"7 7 0.2\n",
"8 8 0.4\n",
"9 9 0.2\n",
"12.200000000000001\n",
"1.4999999999999998\n"
]
}
],
"source": [
"# Create probability distribution\n",
"size_dist = restaurant_groups['group_size'] / restaurant_groups.shape[0]\n",
"\n",
"# Reset index and rename columns\n",
"size_dist = size_dist.reset_index()\n",
"size_dist.columns = ['group_size', 'prob']\n",
"\n",
"print(size_dist)\n",
"\n",
"# Calculate expected value\n",
"expected_value = (size_dist['group_size'] * size_dist['prob']).sum()\n",
"print(expected_value)\n",
"\n",
"# Subset groups of size 4 or more\n",
"groups_4_or_more = size_dist[size_dist['group_size'] >= 4]\n",
"\n",
"# Sum the probabilities of groups_4_or_more\n",
"prob_4_or_more = groups_4_or_more['prob'].sum()\n",
"print(prob_4_or_more)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Continuous distributions\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Data back-ups\n",
"The sales software used at your company is set to automatically back itself up, but no one knows exactly what time the back-ups happen. It is known, however, that back-ups happen exactly every 30 minutes. Amir comes back from sales meetings at random times to update the data on the client he just met with. He wants to know how long he'll have to wait for his newly-entered data to get backed up. Use your new knowledge of continuous uniform distributions to model this situation and answer Amir's questions.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.16666666666666666\n",
"0.8333333333333334\n",
"0.3333333333333333\n"
]
}
],
"source": [
"from scipy.stats import uniform\n",
"\n",
"# Min and max wait times for back-up that happens every 30 min\n",
"min_time = 0\n",
"max_time = 30\n",
"\n",
"# Calculate probability of waiting less than 5 mins\n",
"prob_less_than_5 = uniform.cdf(5, min_time, max_time)\n",
"print(prob_less_than_5)\n",
"\n",
"# Calculate probability of waiting more than 5 mins\n",
"prob_greater_than_5 = 1 - uniform.cdf(5, min_time, max_time)\n",
"print(prob_greater_than_5)\n",
"\n",
"# Calculate probability of waiting 10-20 mins\n",
"prob_between_10_and_20 = uniform.cdf(20, min_time, max_time) - \\\n",
" uniform.cdf(10, min_time, max_time)\n",
"print(prob_between_10_and_20)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Simulating wait times\n",
"To give Amir a better idea of how long he'll have to wait, you'll simulate Amir waiting 1000 times and create a histogram to show him what he should expect. Recall from the last exercise that his minimum wait time is 0 minutes and his maximum wait time is 30 minutes.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 7.144097 0.97455866 3.72802787 5.11644319 8.70602482 24.69140099\n",
" 23.98012075 3.19592668 25.1985306 17.89048629]\n"
]
},
{
"data": {
"image/png": "i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6xyzn/vH/awOutX67Arb+zu70ry1iTvXk7DwH7zwSR/Psl3Jnkyyb9Z7zgHU1V9c5KPJ/nh7v7ddc9zGOywTe2ru9Tdf9Td35ntb3i5Ksm377TauZzpsIfVWb9ah5evu59Yfj6d5OeyvTOzuqeWazCevxbj6TXPc6B191PLP7pfS/IfYj992ZbrVj6e5MPd/Yllsf10BTttU/vq6rr7mSSfSvKGJBdU1fOf03nOf+8f9rDy1TrDqur85aLLVNX5Sf5Gks+/+LN4ie5Mcny5fTzJHWuc5cB7/pf/4m/FfvqyLBcG35rk4e7+8dMesp/u0pm2qX11d6pqo6ouWG5/Y5LvyfZ1a/cmecey2jnfRw/1XwUmyfJnqz+ZP/5qnX+55pEOtKr6tmwfpUq2P7n/P9mmL19VfSTJm7L9zfZPJbkpyX9OcluSP5vk8STv7G4XZL8EZ9ieb8r2qZVO8liSv//8tUGcXVX9tST/PcnnknxtWfwj2b4myH66Cy+yTd8V++rLVlXfke2L08/L9oGi27r7Xyy/pz6a5KIkn03yt7v7D87ZXIc9rAAAzpXDfioQAOCcEVYAAEOEFQDAEGEFADBEWAEADBFWAABDhBUAwBBhBQAw5P8CKXEEHwE2yaMAAAAASUVORK5CYII=\n",
"text/plain": [
""
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Set random seed to 334\n",
"np.random.seed(334)\n",
"\n",
"# Generates 1000 wait times between 0 and 30 mins\n",
"wait_times = uniform.rvs(min_time, max_time, 1000)\n",
"print(wait_times[:10])\n",
"\n",
"# Create a histogram of simulated times and show plot\n",
"plt.hist(wait_times);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The binomial distribution\n",
"- Binomial distribution\n",
" - Probability distribution of the number of successes in a sequence of independent trials\n",
" - Described by $n$ and $p$\n",
" - $n$: total number of trials\n",
" - $p$: probability of success\n",
" - Expected value: $n$ x $p$\n",
" - Independence: The binomial distribution is a probability distribution of the number of successes in a sequence of **independent** trials"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Simulating sales deals\n",
"Assume that Amir usually works on 3 deals per week, and overall, he wins 30% of deals he works on. Each deal has a binary outcome: it's either lost, or won, so you can model his sales deals with a binomial distribution. In this exercise, you'll help Amir simulate a year's worth of his deals so he can better understand his performance."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1]\n",
"[0]\n",
"0.8461538461538461\n"
]
}
],
"source": [
"from scipy.stats import binom\n",
"\n",
"# Set random seed to 10\n",
"np.random.seed(10)\n",
"\n",
"# Simulate a single deal\n",
"print(binom.rvs(1, 0.3, size=1))\n",
"\n",
"# Simulate 1 week of 3 deals\n",
"print(binom.rvs(3, 0.3, size=1))\n",
"\n",
"# Simulate 52 weeks of 3 deals\n",
"deals = binom.rvs(3, 0.3, size=52)\n",
"\n",
"# Print mean deals won per week\n",
"print(np.mean(deals))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Calculating binomial probabilities\n",
"Just as in the last exercise, assume that Amir wins 30% of deals. He wants to get an idea of how likely he is to close a certain number of deals each week. In this exercise, you'll calculate what the chances are of him closing different numbers of deals using the binomial distribution.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.026999999999999982\n",
"0.7839999999999999\n",
"0.21600000000000008\n"
]
}
],
"source": [
"# Probability of closing 3 out of 3 deals\n",
"prob_3 = binom.pmf(3, 3, 0.3)\n",
"print(prob_3)\n",
"\n",
"# Probability of closing <= 1 deal out of 3 deals\n",
"prob_less_than_or_equal_1 = binom.cdf(1, 3, 0.3)\n",
"print(prob_less_than_or_equal_1)\n",
"\n",
"# Probability of closing > 1 deal out of 3 deals\n",
"prob_greater_than_1 = 1 - binom.cdf(1, 3, 0.3)\n",
"print(prob_greater_than_1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### How many sales will be won?\n",
"Now Amir wants to know how many deals he can expect to close each week if his win rate changes. Luckily, you can use your binomial distribution knowledge to help him calculate the expected value in different situations. Recall from the video that the expected value of a binomial distribution can be calculated by $n × p$."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.8999999999999999\n",
"0.75\n",
"1.0499999999999998\n"
]
}
],
"source": [
"# Expected number won with 30% win rate\n",
"won_30pct = 3 * 0.3\n",
"print(won_30pct)\n",
"\n",
"# Expected number won with 25% win rate\n",
"won_25pct = 3 * 0.25\n",
"print(won_25pct)\n",
"\n",
"# Expected number won with 35% win rate\n",
"won_35pct = 3 * 0.35\n",
"print(won_35pct)"
]
}
],
"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.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}