Path: blob/master/lessons/lesson_03/code/central limit theorem (done).ipynb
1904 views
Central Limit Theorem
The central limit theorem is a fundamental tool in statistics. It says, with some assumptions, that sampling distributions are normal with a specific mean and variance. It's a vital tool in data science when working with large data sets. Often a random sample (or many random samples) can tell us crucial information about a much larger dataset.
For example, if you work at a large social media company and you want to estimate the distribution of the ages of your users for targetting ads, you could extract the ages of hundreds of millions of users from your database and compute the distribution. This will take a lot of time and effort, and it's usually enough to simply look at a much smaller but random subset of users.
Sampling Distributions
Usually we do not know the true distribution of our data so we study it by looking at the distribution of random samples. It turns out that we can often identify the underlying "true" distribution within any necessary degree of approximation as long as we can obtain enough data.
Let's start by looking at a typical statistical distribution: the exponential distribution. Here's what it looks like (it goes to so we just look at the front).
This distribution has one parameter and the mean and standard deviation are both the same and equal to .
Sampling
Let's take a look at a random sample from the exponential distribution. Rerun the following cell several times.
A histogram of our random sample looks approximately like our distribution and the sample has a mean and standard deviation in the ballpark of our true parameter values. Let's take a look at the distribution of the means of many such random samples.
The mean of the means is much closer to our actual mean (1). Let's take many samples and see if things get better.
That's really close! The distribution looks like a normal distribution too. Let's do a quick curve fit (called a kernel density estimate). First we'll look at a large sample, and then at the distribution of means of many samples.
The Central Limit Theorem
The central limit theorem explains what we've just observed. It says that, as the size of a sample increases, that:
the mean of the sample converges to the mean of the true distribution, and
the standard deviation of the sample is the same as the true standard deviation
The sampling distribution of the means has:
The same mean as the original distribution
A standard deviation given by the true standard deviation divided by :
This quantity is usually referred to as the standard error.
In practice, we typically use these results as follows. Take a large random sample and calculate the sample mean and the sample deviation . Then the true mean lies, with 95% confidence, in the interval:
As the sample size gets large, the error gets small. So for a large enough sample we can get a very good approximation of the true mean.
Other distributions
Let's try this out with some other distributions. First we select a random distribution.
Now let's look at a random sample.