Last active
October 23, 2019 18:10
-
-
Save chaipi-chaya/8f9b652fdfdc21223df1e7e2e5fdcf78 to your computer and use it in GitHub Desktop.
Illustration with Python Central Limit Theorem | standardize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## standardize part | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import scipy.stats as stats | |
# Step 1 | |
# use last sampling | |
from diffNumSampling import meansample | |
sm = meansample[len(meansample)-1] | |
# Step 2 | |
# calculate start deviation | |
std = np.std(sm) | |
# set population mean | |
mean = np.mean(sm) | |
# list of standarded sample | |
# Step 3 | |
zn = [] | |
# for each sample subtract with mean and devided by standard deviation | |
for i in sm: | |
zn.append((i-mean)/std) | |
# Step 4 | |
# plot hist | |
plt.figure(figsize=(20,10)) | |
plt.hist(zn, 200, density=True) | |
# compare with standard normal disrtibution line | |
mu = 0 | |
sigma = 1 | |
x = np.linspace(mu - 3*sigma, mu + 3*sigma, 100) | |
# draw standard normal disrtibution line | |
plt.plot(x, stats.norm.pdf(x, mu, sigma),linewidth = 5, color='red') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment