{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [ "remove_input" ] }, "outputs": [], "source": [ "path_data = '../../../../data/'\n", "\n", "import numpy as np\n", "import pandas as pd\n", "\n", "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "plt.style.use('fivethirtyeight')\n", "\n", "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Variability ###\n", "The mean tells us where a histogram balances. But in almost every histogram we have seen, the values spread out on both sides of the mean. How far from the mean can they be? To answer this question, we will develop a measure of **variability about the mean**.\n", "\n", "We will start by describing how to calculate the measure. Then we will see why it is a good measure to calcualte." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The Rough Size of Deviations from Average ###\n", "For simplicity, we will begin our calcuations in the context of a simple array `any_numbers` consisting of just four values. As you will see, our method will extend easily to any other array of values." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "any_numbers = np.array([1, 2, 2, 10])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The goal is to measure roughly how far off the numbers are from their average. To do this, we first need the average: " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.75" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Step 1. The average.\n", "\n", "mean = np.mean(any_numbers)\n", "mean" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, let's find out how far each value is from the mean. These are called the *deviations from the average*. A \"deviation from average\" is just a value minus the average. The table `calculation_steps` displays the results." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ValueDeviation from Average
01-2.75
12-1.75
22-1.75
3106.25
\n", "
" ], "text/plain": [ " Value Deviation from Average\n", "0 1 -2.75\n", "1 2 -1.75\n", "2 2 -1.75\n", "3 10 6.25" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Step 2. The deviations from average.\n", "\n", "deviations = any_numbers - mean\n", "calculation_steps = pd.DataFrame(\n", " {'Value':any_numbers,\n", " 'Deviation from Average':deviations}\n", " )\n", "calculation_steps" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Some of the deviations are negative; those correspond to values that are below average. Positive deviations correspond to above-average values.\n", "\n", "To calculate roughly how big the deviations are, it is natural to compute the mean of the deviations. But something interesting happens when all the deviations are added together:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.sum(deviations)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The positive deviations exactly cancel out the negative ones. This is true of all lists of numbers, no matter what the histogram of the list looks like: **the sum of the deviations from average is zero.** \n", "\n", "Since the sum of the deviations is 0, the mean of the deviations will be 0 as well:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.mean(deviations)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Because of this, the mean of the deviations is not a useful measure of the size of the deviations. What we really want to know is roughly how big the deviations are, regardless of whether they are positive or negative. So we need a way to eliminate the signs of the deviations.\n", "\n", "There are two time-honored ways of losing signs: the **absolute value**, and the **square**. It turns out that taking the square constructs a measure with extremely powerful properties, some of which we will study in this course.\n", "\n", "So let's eliminate the signs by squaring all the deviations. Then we will take the mean of the squares:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ValueDeviation from AverageSquared Deviations from Average
01-2.757.5625
12-1.753.0625
22-1.753.0625
3106.2539.0625
\n", "
" ], "text/plain": [ " Value Deviation from Average Squared Deviations from Average\n", "0 1 -2.75 7.5625\n", "1 2 -1.75 3.0625\n", "2 2 -1.75 3.0625\n", "3 10 6.25 39.0625" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Step 3. The squared deviations from average\n", "\n", "squared_deviations = deviations ** 2\n", "calculation_steps['Squared Deviations from Average'] = squared_deviations\n", "calculation_steps" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "13.1875" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Step 4. Variance = the mean squared deviation from average\n", "\n", "variance = np.mean(squared_deviations)\n", "variance" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Variance:** The mean squared deviation calculated above is called the *variance* of the values. \n", "\n", "While the variance does give us an idea of spread, it is not on the same scale as the original variable as its units are the square of the original. This makes interpretation very difficult. \n", "\n", "So we return to the original scale by taking the positive square root of the variance:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.6314597615834874" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Step 5.\n", "# Standard Deviation: root mean squared deviation from average\n", "# Steps of calculation: 5 4 3 2 1\n", "\n", "sd = variance ** 0.5\n", "sd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Standard Deviation ###\n", "\n", "The quantity that we have just computed is called the *standard deviation* of the list, and is abbreviated as SD. It measures roughly how far the numbers on the list are from their average.\n", "\n", "**Definition.** The SD of a list is defined as the *root mean square of deviations from average*. That's a mouthful. But read it from right to left and you have the sequence of steps in the calculation.\n", "\n", "**Computation.** The five steps described above result in the SD. You can also use the function ``np.std`` to compute the SD of values in an array:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.6314597615834874" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.std(any_numbers)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Working with the SD ###\n", "\n", "To see what we can learn from the SD, let's move to a more interesting dataset than `any_numbers`. The table `nba13` contains data on the players in the National Basketball Association (NBA) in 2013. For each player, the table records the position at which the player usually played, his height in inches, his weight in pounds, and his age in years." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NamePositionHeightWeightAge in 2013
0DeQuan JonesGuard8022123
1Darius MillerGuard8023523
2Trevor ArizaGuard8021028
3James JonesGuard8021532
4Wesley JohnsonGuard7921526
..................
500Joel AnthonyCenter8124531
501Bismack BiyomboCenter8122921
502Luis ScolaCenter8124533
503Lavoy AllenCenter8122524
504Boris DiawCenter8023531
\n", "

505 rows × 5 columns

\n", "
" ], "text/plain": [ " Name Position Height Weight Age in 2013\n", "0 DeQuan Jones Guard 80 221 23\n", "1 Darius Miller Guard 80 235 23\n", "2 Trevor Ariza Guard 80 210 28\n", "3 James Jones Guard 80 215 32\n", "4 Wesley Johnson Guard 79 215 26\n", ".. ... ... ... ... ...\n", "500 Joel Anthony Center 81 245 31\n", "501 Bismack Biyombo Center 81 229 21\n", "502 Luis Scola Center 81 245 33\n", "503 Lavoy Allen Center 81 225 24\n", "504 Boris Diaw Center 80 235 31\n", "\n", "[505 rows x 5 columns]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nba13 = pd.read_csv(path_data + 'nba2013.csv')\n", "nba13" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is a histogram of the players' heights." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjMAAAFZCAYAAABt1a5jAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAs+klEQVR4nO3deVRV9f7/8dfxJIMjRQaoOFwkHHJOpUyz4aplDjmb95vLnNK6XUtKbdCVw0WNJov42rVB+6pFRpbDN1etrNSy0hz4ZhaKKCJRqEAoHqbz++Mu+V1k2ofO5px9fD7Waq3OHj77/TmbDS/38Nm2nJwcpwAAACyqnqcLAAAA+DMIMwAAwNIIMwAAwNIIMwAAwNIIMwAAwNIIMwAAwNIIMwAAwNIIMwAAwNKuyDCTkpLi6RLqFP31bfTXt9Ff30Z/3eOKDDMAAMB3EGYAAIClEWYAAIClEWYAAIClEWYAAIClEWYAAIClEWYAAIClEWYAAIClEWYAAIClEWYAAIClEWYAAIClXeXpAgAAnpOZ6aeMDPP+XduiRanCwgpNax+QCDMAcEXLyKinmBi7ae3HxUlhYaY1D0jiMhMAALA4wgwAALA0wgwAALA0wgwAALA0wgwAALA0wgwAALA0wgwAALA0wgwAALA0wgwAALA0wgwAALA0wgwAALA0w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UKGVnZ+tf//qXOnbsWOkNwEZ0795dkrR48WKNGjVKfn5+6t+/v5o1a1brfgKoG4QZAB4xYsQIhYWF6YUXXtBrr72mgoIChYSE6MYbb9T9999f7boPPPCAJGnlypVauHChIiMjtWrVKq1fv15HjhypVT29evXS008/rbffflsPPfSQSktLtXnzZsIMYAG2nJwc7oAD4BP69u2rZs2aadOmTZ4uBUAd4p4ZAJZz8eLFCk8iffnll/rxxx/Vv39/D1UFwFM4MwPAcnbu3Km5c+dq2LBhCg0N1U8//aS3335bwcHB+vrrrxUUFOTpEgHUIe6ZAWA5rVq1UuvWrfXWW2/p7NmzatKkie655x4tWLCAIANcgTgzAwAALI17ZgAAgKURZgAAgKURZgAAgKURZgAAgKURZgAAgKURZgAAgKX9P07FJXoGEydpAAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "unit = ''\n", "\n", "fig, ax = plt.subplots(figsize=(8,5))\n", "\n", "ax.hist(nba13['Height'], bins=np.arange(68, 88, 1), density=True, color='blue', alpha=0.8, ec='white', zorder=5)\n", "\n", "y_vals = ax.get_yticks()\n", "\n", "y_label = 'Percent per ' + (unit if unit else 'unit')\n", "\n", "x_label = 'Height'\n", "\n", "ax.set_yticklabels(['{:g}'.format(x * 100) for x in y_vals])\n", "\n", "plt.ylabel(y_label)\n", "\n", "plt.xlabel(x_label)\n", "\n", "plt.title('');\n", "\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is no surprise that NBA players are tall! Their average height is just over 79 inches (6'7\"), about 10 inches taller than the average height of men in the United States." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "79.06534653465347" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mean_height = np.mean(nba13['Height'])\n", "mean_height" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "About how far off are the players' heights from the average? This is measured by the SD of the heights, which is about 3.45 inches." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.450597183027555" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sd_height = np.std(nba13['Height'])\n", "sd_height" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The towering center Hasheem Thabeet of the Oklahoma City Thunder was the tallest player at a height of 87 inches." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NamePositionHeightWeightAge in 2013
413Hasheem ThabeetCenter8726326
414Roy HibbertCenter8627826
415Alex LenCenter8525520
\n", "
" ], "text/plain": [ " Name Position Height Weight Age in 2013\n", "413 Hasheem Thabeet Center 87 263 26\n", "414 Roy Hibbert Center 86 278 26\n", "415 Alex Len Center 85 255 20" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nba13.sort_values(by=['Height'], ascending=False).head(3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Thabeet was about 8 inches above the average height." ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "7.934653465346528" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "87 - mean_height" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "That's a deviation from average, and it is about 2.3 times the standard deviation:" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.299501519439792" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(87 - mean_height)/sd_height" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In other words, the height of the tallest player was about 2.3 SDs above average.\n", "\n", "At 69 inches tall, Isaiah Thomas was one of the two shortest NBA players in 2013. His height was about 2.9 SDs below average." ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NamePositionHeightWeightAge in 2013
201Nate RobinsonGuard6918029
200Isaiah ThomasGuard6918524
199Phil PresseyGuard7117522
\n", "
" ], "text/plain": [ " Name Position Height Weight Age in 2013\n", "201 Nate Robinson Guard 69 180 29\n", "200 Isaiah Thomas Guard 69 185 24\n", "199 Phil Pressey Guard 71 175 22" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nba13.sort_values(by=['Height']).head(3)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-2.916986828877584" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(69 - mean_height)/sd_height" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What we have observed is that the tallest and shortest players were both just a few SDs away from the average height. This is an example of why the SD is a useful measure of spread. No matter what the shape of the histogram, the average and the SD together tell you a lot about where the histogram is situated on the number line." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### First main reason for measuring spread by the SD\n", "\n", "**Informal statement.** In all numerical data sets, the bulk of the entries are within the range \"average $\\pm$ a few SDs\".\n", "\n", "For now, resist the desire to know exactly what fuzzy words like \"bulk\" and \"few\" mean. We wil make them precise later in this section. Let's just examine the statement in the context of some more examples." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have already seen that *all* of the heights of the NBA players were in the range \"average $\\pm$ 3 SDs\". \n", "\n", "What about the ages? Here is a histogram of the distribution, along with the mean and SD of the ages." ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAFZCAYAAACG4hVgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAshUlEQVR4nO3deXQU5Z7G8acJZGEzTMQQIBAkQSCgILIo7rIIyCJBAfGOo4JKRC9egxCvorJMIwa87OKg90TFKwGCIi5cPSBiEGURBBENxkjYgixJDIbGpHv+cOixSTqp9JLuMt/POTnHrqq36tfveRMeq96qshQUFDgEAABgInUCXQAAAEB1EWAAAIDpEGAAAIDpEGAAAIDpEGAAAIDpEGAAAIDpEGAAAIDpEGAAAIDpEGAMyM7ODnQJpkXfeYZ+8xx95xn6zXP0nee86TsCDAAAMB0CDAAAMB0CDAAAMB0CDAAAMB0CDAAAMB0CDAAAMB0CDAAAMB0CDAAAMB0CDAAAMJ2ABpisrCyNGjVKHTp0UGRkpJYvX+6y3uFwyGq1qn379mrWrJkGDRqkb7/9NkDVAgCAYBHQAHPmzBl17NhRs2bNUkRERLn18+bN06JFi/T8889rw4YNatq0qW6//Xb98ssvAagWAAAEi7qBPHi/fv3Ur18/SVJycrLLOofDoSVLlmjixIkaOnSoJGnJkiVKSEjQqlWrdO+999Z4vahdjh4N1eHDnmf8iy6qo8JCu0dtw8NjPD4uANQGAQ0wlfnpp5+Un5+vm2++2bksIiJC11xzjb744gsCDPzu8OE6SkkJ8bh9aqpktXrWfurUMI+PCwC1QdAGmPz8fElS06ZNXZY3bdpUR48eddvOX28F5W2jnjNr3xUVxclmK39p06jffguRzVbmcXuz9lswoO88Q795jr7zXEV9l5CQUGW7oA0w51ksFpfPDoej3LI/MvKlqys7O9sv+60NzNx3hYXhCgvz/AxMvXpSWJinv2Ilpu23QDPzmAsk+s1z9J3nvOm7oL2NOjo6WpJ0/Phxl+UnTpwod1YGAAD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P9GmJkpAsyyZcs0f/585efnq3379rJarbrmmmtq7PjHj4dp2jTP/yFPS5NiAvSqDG8fkc3sfACo3KlTIUpLM+e/EWYW9JeQMjMzNWXKFD3++OP69NNP1aNHD91xxx3Ky8sLdGkAACBAgj7ALFq0SHfddZfuueceXXbZZXrhhRcUHR2tV199NdClAQCAAAnqAHPu3Dnt2rVLN998s8vym2++WV988UWN1dG4caMaO9afTb16prhKGXToN8/Rd56h3zxH33kuISHB47aWgoIChw9r8amjR4+qQ4cOeu+999S7d2/n8ueff14rV67U9u3bA1gdAAAIlKA+A3OexWJx+exwOMotAwAAtUdQB5ioqCiFhITo+PHjLstPnDihpk2bBqgqAAAQaEEdYEJDQ9WlSxdt3LjRZfnGjRvVs2fPAFUFAAACLehnHj388MN68MEH1a1bN/Xs2VOvvvqqjh07pnvvvTfQpQEAgAAJ6jMwkjR8+HBZrVa98MILuu6667R161ZlZGSoVatWPj1OVlaWRo0apQ4dOigyMlLLly93WT9+/HhFRka6/PTp08enNZjR3LlzddNNNyk2NlZt27bVyJEjtW/fPpdtHA6HrFar2rdvr2bNmmnQoEH69ttvA1RxcDDSb4y5iv3P//yPrrnmGsXGxio2NlZ9+/bV+vXrnesZb+5V1XeMOWPmzJmjyMhITZo0ybmMcVe1ivrNmzEX9AFGksaOHas9e/bo+PHj2rRpk8sdSb5y5swZdezYUbNmzVJERESF29x444367rvvnD8rV670eR1m89lnn+n+++/X+vXrtXbtWtWtW1fDhg3T6dOnndvMmzdPixYt0vPPP68NGzaoadOmuv322/XLL78EsPLAMtJvEmOuIs2bN9dzzz2nTZs2aePGjbr++us1ZswY7d27VxLjrTJV9Z3EmKvKtm3blJ6ersTERJfljLvKues3yfMxF/SXkGpKv3791K9fP0lScnJyhduEhYUpOjq6JssKepmZmS6fly5dqlatWmnr1q0aMGCAHA6HlixZookTJ2ro0KGSpCVLlighIUGrVq2qtZcCq+q38xhz5Q0aNMjl89NPP61XXnlF27ZtU2JiIuOtEpX1XadOnSQx5ipTWFiocePGacGCBZo9e7ZzOX/nKueu387zdMyZ4gxMsPj8888VHx+vbt266dFHH9XPP/8c6JKCTnFxsex2uyIjIyVJP/30k/Lz810eRhgREaFrrrmmRh9GGOwu7LfzGHOVKysr0+rVq3XmzBn16NGD8VYNF/bdeYw5984HlBtuuMFlOeOucu767TxPxxxnYAzq06ePBg8erNatW+vgwYOaMWOGhgwZok8++URhYWGBLi9oTJkyRZ07d3b+QczPz5ekcre9N23aVEePHq3x+oLVhf0mMeYq880336hfv346e/asGjRooDfeeEOJiYnOfywYb+656zuJMVeZ9PR05eTkaOnSpeXW8XfOvcr6TfJuzBFgDEpKSnL+d2Jiorp06aLOnTtr/fr1GjJkSAArCx5PPvmktm7dqg8//FAhIa5vZuVhhO656zfGnHsJCQnavHmzCgsLtXbtWo0fP17r1q1zrme8ueeu7zp27MiYcyM7O1vTpk3TBx98oNDQULfbMe5cGek3b8YcAcZDMTExat68uXJycgJdSlBITU1VZmam3n33XcXFxTmXn7+uefz4cbVs2dK5nIcR/s5dv1WEMff/QkNDdemll0qSunbtqp07d2rx4sVKSUmRxHirjLu+W7hwYbltGXO/+/LLL3Xy5EldffXVzmVlZWXasmWLXn31VW3dulUS4+5CVfXbkSNHyp1lqc6YYw6Mh06ePKmjR48y2U3S5MmTtWrVKq1du1bt2rVzWde6dWtFR0e7PIzw7Nmz+vzzz2v9wwgr67eKMObcs9vtOnfuHOPNA+f7riKMud8NGjRIW7Zs0ebNm50/Xbt2VVJSkjZv3qz4+HjGXQWq6reKzspUZ8xxBub/FBcXOxOf3W7XoUOH9PXXX6tJkyZq0qSJZs2apSFDhig6OloHDx7UtGnT1LRpU912220BrjywUlJStGLFCr3xxhuKjIx0Xgtu0KCBGjZsKIvFovHjx2vOnDlKSEhQfHy80tLS1KBBA40YMSLA1QdOVf1WXFzMmHPj2WefVb9+/dSiRQsVFxdr1apV+uyzz5SRkcF4q0JlfceYc+/880n+qH79+mrSpIk6duwoSYy7ClTVb96OOQLM//nqq680ePBg52er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DhUXFxMgAG8xBwYoBY4f4mob9++uu2228r9PPzww7Lb7Vq1apUkqU+fPpKkl19+2WU/S5YsKbfv4cOHa+fOnXr//ffLrSspKanwibb+lpOTo9tvv10XXXSRMjMz3b6qoF27durYsaPS09N17tw55/IVK1aooKBAQ4cO9ej4P//8c7llp0+f1nvvvaeWLVuqadOmHu0XwP/jDAxQC5yfpDtw4MAK18fFxalDhw5asWKFHn30UV1xxRUaPny4Xn31VRUUFKh379766quv9MknnygqKsrl6bSPPPKI/v3vf+svf/mL7rzzTnXr1k02m00HDhzQmjVrtHLlSnXv3r2mvqp++eUXDR06VD///LOmTJmiTZs2uaxv06aNy5OHZ86cqaSkJA0ZMsT5JN6FCxfq2muv1eDBg13avvXWW8rLy3N+3r17t1544QVJv99x1KpVK0lS//791alTJ3Xt2lVRUVE6ePCg3njjDR0/flz//Oc//fXVgVqFAAPUAitWrFBoaGill0RuvfVWvfjii9q7d686deqkxYsX65JLLtHKlSv14YcfqkePHlqzZo369+/v8tj/iIgIrV27VvPmzVNmZqZWr16tBg0aKC4uTuPHj1dCQkJNfEWnU6dOOUOG1Wott3706NEuAeamm25SRkaG/vu//1tTpkxRo0aN9Je//EVTp051CWqS9Prrr7u8z2jnzp3auXOnJKlXr17OAPNf//VfWrdunRYsWKCioiI1adJE3bt314QJEzy6pRxAebxKAIBhBQUFiouL01NPPaWUlJRAlwOgFmMODIAKVfQMlIULF0qSrr/++pouBwBccAkJQIXmzZunbdu26YYbblBERISysrL09ttvq2/fvgF9ezUASFxCAuDGxo0bNXv2bO3fv1/FxcVq1qyZhg0bptTU1ApvSQaAmkSAAQAApsMcGAAAYDoEGAAAYDoEGAAAYDoEGAAAYDoEGAAAYDoEGAAAYDr/C9OWVrha0YGMAAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "unit = ''\n", "\n", "fig, ax = plt.subplots(figsize=(8,5))\n", "\n", "ax.hist(nba13['Age in 2013'], bins=np.arange(15, 45, 1), density=True, color='blue', alpha=0.8, ec='white', zorder=5)\n", "\n", "y_vals = ax.get_yticks()\n", "\n", "y_label = 'Percent per ' + (unit if unit else 'unit')\n", "\n", "x_label = 'Age in 2013'\n", "\n", "ax.set_yticklabels(['{:g}'.format(x * 100) for x in y_vals])\n", "\n", "plt.ylabel(y_label)\n", "\n", "plt.xlabel(x_label)\n", "\n", "plt.title('');\n", "\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(26.19009900990099, 4.321200441720307)" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ages = nba13['Age in 2013']\n", "mean_age = np.mean(ages)\n", "sd_age = np.std(ages)\n", "mean_age, sd_age" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The average age was just over 26 years, and the SD was about 4.3 years.\n", "\n", "How far off were the ages from the average? Just as we did with the heights, let's look at the two extreme values of the ages.\n", "\n", "Juwan Howard was the oldest player, at 40. " ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NamePositionHeightWeightAge in 2013
294Juwan HowardForward8125040
172Derek FisherGuard7321039
466Marcus CambyCenter8323539
\n", "
" ], "text/plain": [ " Name Position Height Weight Age in 2013\n", "294 Juwan Howard Forward 81 250 40\n", "172 Derek Fisher Guard 73 210 39\n", "466 Marcus Camby Center 83 235 39" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nba13.sort_values(by=['Age in 2013'], ascending=False).head(3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Howard's age was about 3.2 SDs above average." ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.1958482778922357" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(40 - mean_age)/sd_age" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The youngest was 15-year-old Jarvis Varnado, who won the NBA Championship that year with the Miami Heat. His age was about 2.6 SDs below average." ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NamePositionHeightWeightAge in 2013
293Jarvis VarnadoForward8123015
296Giannis AntetokounmpoForward8120518
277Livio Jean-CharlesForward8121719
\n", "
" ], "text/plain": [ " Name Position Height Weight Age in 2013\n", "293 Jarvis Varnado Forward 81 230 15\n", "296 Giannis Antetokounmpo Forward 81 205 18\n", "277 Livio Jean-Charles Forward 81 217 19" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nba13.sort_values(by=['Age in 2013']).head(3)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-2.589581103867081" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(15 - mean_age)/sd_age" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What we have observed for the heights and ages is true in great generality. For *all* lists, the bulk of the entries are no more than 2 or 3 SDs away from the average. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Chebychev's Bounds ###\n", "The Russian mathematician [Pafnuty Chebychev](https://en.wikipedia.org/wiki/Pafnuty_Chebyshev) (1821-1894) proved a result that makes our rough statements precise.\n", "\n", "**For all lists, and all numbers $z$, the proportion of entries that are in the range\n", "\"average $\\pm z$ SDs\" is at least $1 - \\frac{1}{z^2}$.**\n", "\n", "It is important to note that the result gives a bound, not an exact value or an approximation.\n", "\n", "What makes the result powerful is that it is true for all lists – all distributions, no matter how irregular. \n", "\n", "Specifically, it says that for every list:\n", "\n", "- the proportion in the range \"average $\\pm$ 2 SDs\" is **at least 1 - 1/4 = 0.75**\n", "\n", "- the proportion in the range \"average $\\pm$ 3 SDs\" is **at least 1 - 1/9 $\\approx$ 0.89**\n", "\n", "- the proportion in the range \"average $\\pm$ 4.5 SDs\" is **at least 1 - 1/$\\boldsymbol{4.5^2}$ $\\approx$ 0.95**\n", "\n", "As we noted above, Chebychev's result gives a lower bound, not an exact answer or an approximation. For example, the percent of entries in the range \"average $\\pm ~2$ SDs\" might be quite a bit larger than 75%. But it cannot be smaller." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Standard units\n", "\n", "In the calculations above, the quantity $z$ measures *standard units*, the number of standard deviations above average.\n", "\n", "Some values of standard units are negative, corresponding to original values that are below average. Other values of standard units are positive. But no matter what the distribution of the list looks like, Chebychev's bounds imply that standard units will typically be in the (-5, 5) range.\n", "\n", "To convert a value to standard units, first find how far it is from average, and then compare that deviation with the standard deviation.\n", "$$\n", "z ~=~ \\frac{\\mbox{value }-\\mbox{ average}}{\\mbox{SD}}\n", "$$\n", "\n", "As we will see, standard units are frequently used in data analysis. So it is useful to define a function that converts an array of numbers to standard units." ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "def standard_units(numbers_array):\n", " \"Convert any array of numbers to standard units.\"\n", " return (numbers_array - np.mean(numbers_array))/np.std(numbers_array) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example ###\n", "As we saw in an earlier section, the table `united` contains a column `Delay` consisting of the departure delay times, in minutes, of over thousands of United Airlines flights in the summer of 2015. We will create a new column called `Delay (Standard Units)` by applying the function `standard_units` to the column of delay times. This allows us to see all the delay times in minutes as well as their corresponding values in standard units. " ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DateFlight NumberDestinationDelayDelay (Standard Units)
06/1/1573HNL2576.087655
16/1/15217EWR280.287279
26/1/15237STL-3-0.497924
36/1/15250SAN0-0.421937
46/1/15267PHL641.199129
..................
138208/31/151978LAS-4-0.523254
138218/31/151993IAD8-0.219304
138228/31/151994ORD3-0.345950
138238/31/152000PHX-1-0.447266
138248/31/152013EWR-2-0.472595
\n", "

13825 rows × 5 columns

\n", "
" ], "text/plain": [ " Date Flight Number Destination Delay Delay (Standard Units)\n", "0 6/1/15 73 HNL 257 6.087655\n", "1 6/1/15 217 EWR 28 0.287279\n", "2 6/1/15 237 STL -3 -0.497924\n", "3 6/1/15 250 SAN 0 -0.421937\n", "4 6/1/15 267 PHL 64 1.199129\n", "... ... ... ... ... ...\n", "13820 8/31/15 1978 LAS -4 -0.523254\n", "13821 8/31/15 1993 IAD 8 -0.219304\n", "13822 8/31/15 1994 ORD 3 -0.345950\n", "13823 8/31/15 2000 PHX -1 -0.447266\n", "13824 8/31/15 2013 EWR -2 -0.472595\n", "\n", "[13825 rows x 5 columns]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "united = pd.read_csv(path_data + 'united_summer2015.csv')\n", "\n", "united['Delay (Standard Units)'] = standard_units(united['Delay'])\n", "\n", "united" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The standard units that we can see are consistent with what we expect based on Chebychev's bounds. Most are of quite small size; only one is above 6.\n", "\n", "But something rather alarming happens when we sort the delay times from highest to lowest. The standard units that we can see are extremely high!" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DateFlight NumberDestinationDelayDelay (Standard Units)
31406/21/151964SEA58014.268971
31546/22/15300HNL53713.179818
30696/21/151149IAD50812.445272
28886/20/15353ORD50512.369285
126278/23/151589ORD45811.178815
..................
135688/30/15602SAN-13-0.751216
125038/22/151723KOA-14-0.776545
29006/20/15464PDX-15-0.801874
125658/23/15587PDX-16-0.827203
7886/6/15525IAD-16-0.827203
\n", "

13825 rows × 5 columns

\n", "
" ], "text/plain": [ " Date Flight Number Destination Delay Delay (Standard Units)\n", "3140 6/21/15 1964 SEA 580 14.268971\n", "3154 6/22/15 300 HNL 537 13.179818\n", "3069 6/21/15 1149 IAD 508 12.445272\n", "2888 6/20/15 353 ORD 505 12.369285\n", "12627 8/23/15 1589 ORD 458 11.178815\n", "... ... ... ... ... ...\n", "13568 8/30/15 602 SAN -13 -0.751216\n", "12503 8/22/15 1723 KOA -14 -0.776545\n", "2900 6/20/15 464 PDX -15 -0.801874\n", "12565 8/23/15 587 PDX -16 -0.827203\n", "788 6/6/15 525 IAD -16 -0.827203\n", "\n", "[13825 rows x 5 columns]" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "united.sort_values(by=['Delay'], ascending=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What this shows is that it is possible for data to be many SDs above average (and for flights to be delayed by almost 10 hours). The highest value of delay is more than 14 in standard units. \n", "\n", "However, the proportion of these extreme values is small, and Chebychev's bounds still hold true. For example, let us calculate the percent of delay times that are in the range \"average $\\pm$ 3 SDs\". This is the same as the percent of times for which the standard units are in the range (-3, 3). That is about 98%, as computed below, consistent with Chebychev's bound of \"at least 89%\". " ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.9790235081374322" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "within_3_sd = united[(united['Delay (Standard Units)'] >= -3) & (united['Delay (Standard Units)'] <= 3)]\n", "len(within_3_sd)/len(united)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The histogram of delay times is shown below, with the horizontal axis in standard units. By the table above, the right hand tail continues all the way out to $z=14.27$ standard units (580 minutes). The area of the histogram outside the range $z=-3$ to $z=3$ is about 2%, put together in tiny little bits that are mostly invisible in the histogram." ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAFZCAYAAABkPg4ZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAA29klEQVR4nO3deVxVdeL/8fcVRRBRjBAXUAxQ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l5uamPn36FHteAADgeIW6Q3Fxadq0qRYuXKiYmBhNmTJFPj4+evXVVzV06FDLmBdffFEZGRmKjIxUamqqQkJCtHz5cu5xAwBAKVWiy40kdejQQR06dMhzv8lkUnR0tKKjo4sxFQAAKKkK9PgFAACAko5yAwAADIVyAwAADIVyAwAADMXmctOoUSOtXr06z/1r1qxRo0aNiiQUAABAYdlcbk6cOKGrV6/muf/q1as6efJkkYQCAAAorAKdlsrvjsOHDh3i3jIAAMDh8r3PzaJFi/Tpp59aXk+dOlXz58/PNS41NVU///xzvvejAQAAKA75lpurV68qOTnZ8jotLU05OTlWY0wmkypUqKDBgwcrKirKPikBAABslG+5GTZsmIYNGyZJeuCBBzRx4kR17ty5WIIBAAAUhs2PX9i3b589cwAAABSJAj9b6vLlyzp16pQuXboks9mca3/Lli2LJBgAAEBh2FxuLl26pLFjx2rFihXKzs7Otd9sNstkMunixYtFGhAAAKAgbC43L730kr766isNGzZMLVu2lIeHhx1jAQAAFI7N5WbdunUaMWKE3nrrLXvmAQAAuCM238TP2dlZ/v7+9swCAABwx2wuN927d9fXX39tzywAAAB3zOZy8/zzz+vcuXN69tlntXPnTp07d06//fZbrj8AAACOZPOam5CQEJlMJu3Zs0cJCQl5juNqKQAA4Eg2l5tXXnkl3wdnAgAAlAQ2l5vo6Gh75gAAACgSNq+5uVl2drYuXryo69evF3UeAACAO1KgcvP999+rR48eqlGjhgICArRlyxZJUkpKivr166eNGzfaJSQAAICtbC43O3bsUOfOnXX06FGFhoZaPVfK09NTV65c0ccff2yXkAAAALayudz861//kr+/v7Zv365x48bl2v/II49o165dRRoOAACgoGwuN99//72efPJJubi43PKqqZo1ayo5OblIwwEAABSUzeWmTJkyKlMm7+HJyclydXUtklAAAACFZXO5ady4sdasWXPLfVlZWVqyZIkefvjhIgsGAABQGDaXm5dfflmbNm3SqFGjtH//fknSuXPntG7dOnXr1k1Hjx7V6NGj7RYUAADAFjbfxK9t27aaM2eOIiMjtWjRIklSeHi4zGazKleurHnz5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yiXvFihW1e/duffbZZwoJCdGAAQMKMgX5atKkiT766CNNnDhRAQEBcnNzU6dOndSzZ095eXmpefPmqlq1qo4ePaq5c+cqODhYQUFBlq/fvXu30tPT1aVLlyLLBNwpyg1gZzdOcTg7O6tKlSoKDg5WbGysBg0alGuNQkBAgDZs2KDJkydryZIlunDhgjw9PVWvXj3961//uu3nlCtXTitWrNAnn3yixo0ba9myZXrjjTduOb5KlSrq0KGDvvzyS5uukrrB09NTnTp10vLly60enPn000+rQoUK2rhxo/73v/8pLS1NVapU0YMPPqhRo0ZZnUrp0aOHduzYoRUrVmjp0qUym83au3evAgICtHDhQsXExGj8+PHy9PRUaGioWrVqpZ49e9qc8WYmk0mLFi3S66+/rs8//1wrVqxQ69attWTJEtWvX99qbEHn8FaCg4O1YsUKvf7665oyZYq8vLw0ZMgQeXl5adSoUTa9x5gxY+Tn56f3339fU6dOVVZWlnx9fRUREaHRo0fL2dm5QHOQn6ioKJ09e1bvvvuu0tPT5evrq06dOiksLExLlixRfHy8Ll++rGrVqmnQoEGKjIy0Kpuff/65atasyd2JUaKYUlNT7XPbTAAl3pAhQ7Rlyxb99NNPBXpswK5du/TEE0/o22+/tZyqQOmTkZGhhg0b6uWXX873BpNAcWPNDVBKpaSkaNWqVerXr1+Bn4f04IMPqlOnTrmumkHp8vHHH6t8+fIaMmSIo6MAVjhyA5Qyx44d0/bt27Vo0SJt27ZNO3futLoyCQDudqy5AUqZLVu26LnnnpOPj4/i4uIoNgAMhyM3AADAUFhzAwAADIVyAwAADIVyAwAADIVyAwAADIVyAwAADIVyAwAADOX/AW52TmvDEy6nAAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "unit = ''\n", "\n", "fig, ax = plt.subplots(figsize=(8,5))\n", "\n", "ax.hist(united['Delay (Standard Units)'], bins=np.arange(-5, 15.5, 0.5), \n", " density=True, color='blue', alpha=0.8, ec='white', zorder=5)\n", "\n", "y_vals = ax.get_yticks()\n", "\n", "y_label = 'Percent per ' + (unit if unit else 'unit')\n", "\n", "x_label = 'Delay (Standard Units)'\n", "\n", "plt.xticks(np.arange(-6, 17, 3))\n", "\n", "ax.set_yticklabels(['{:g}'.format(x * 100) for x in y_vals])\n", "\n", "plt.ylabel(y_label)\n", "\n", "plt.xlabel(x_label)\n", "\n", "plt.title('');\n", "\n", "plt.show()" ] } ], "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.6.12" } }, "nbformat": 4, "nbformat_minor": 1 }