[英]Mean of normal distribution generated using numpy.random.randn() is not '0'
I am trying to follow this tutorial from quantopian where they are trying to show that samples progressively exhibit characteristics of a normal distribution with increase in size.我正在尝试从 quantopian 遵循本教程,他们试图证明样本随着大小的增加逐渐表现出正态分布的特征。
I tried to generate a normal distribution using the numpy.random.randn()
method as shown in the tutorial.我尝试使用numpy.random.randn()
方法生成正态分布,如教程中所示。
I understand that this method returns a sample of the standard normal distribution and that for a normal distribution, mean = 0
and standard deviation = 1
我了解此方法返回标准正态分布的样本,对于正态分布, mean = 0
且standard deviation = 1
But , when I check the mean and standard deviation of this distribution, they show weird values ie mean = 0.23
and standard deviation = 0.49
.但是,当我检查该分布的均值和标准差时,它们显示出奇怪的值,即mean = 0.23
和standard deviation = 0.49
。
CODE:代码:
import numpy as np
import matplotlib.pyplot as plt
#np.random.seed(123)
normal = np.random.randn(6)
print (normal.mean())
print (normal.std())
RESULT:结果:
0.231567632423
0.488577812058
I am guessing this could be because I am looking at just a sample and not the whole distribution and it is not perfectly normal.我猜这可能是因为我只看一个样本而不是整个分布,这并不完全正常。 But if that is the case:但如果是这样的话:
What characteristics should I expect from this sample?我应该从这个样本中得到什么特征?
Isn't the tutorial's suggestion wrong, since it will never be a normal distribution?教程的建议是不是错误的,因为它永远不会是正态分布?
You have a sample size or 6. It is not sufficiently large enough to get close to approximating the normal distribution.您的样本大小为 6。它不够大,无法接近正态分布。 Try it with 600 or 6000 to get a good representation of the distribution.尝试使用 600 或 6000 以获得分布的良好表示。
import numpy as np
x = np.random.randn(600)
x.mean(), x.std()
# returns:
(-0.07760043571247623, 0.9664411074909558)
x = np.random.randn(6000)
x.mean(), x.std()
# returns:
(0.003908119246211815, 1.0001989021750033)
The average roll of a 6-sided die should be 3.5. 6 面骰子的平均掷骰数应为 3.5。 However, if you only roll it 6 times, it is unlikely you will have an average of 3.5.但是,如果您只滚动 6 次,您的平均数不太可能达到 3.5。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.