解释正态分布的 Y 值
Interpreting the Y values of a normal distribution
我编写了这段代码来生成一组值 1,2,3 的正态分布:
import pandas as pd
import random
import numpy as np
df = pd.DataFrame({'col1':[1,2,3]})
print(df)
fig, ax = plt.subplots(1,1)
df.plot(kind='hist', normed=True, ax=ax)
Returns :
X 值是可能值的范围,但 Y 值是如何解释的?
读取 http://www.stat.yale.edu/Courses/1997-98/101/normal.htm Y 值使用以下方法计算:
A normal distribution has a bell-shaped density curve described by its
mean and standard deviation . The density curve is symmetrical,
centered about its mean, with its spread determined by its standard
deviation. The height of a normal density curve at a given point x is
given by
这个公式是什么意思?
我认为您在这里混淆了两个概念。直方图只会绘制某个值出现的次数。因此,对于 [1,2,3]
的列表,值 1
将出现一次并且 2
和 3
的值相同。如果你设置 Normed=False
你会得到你现在拥有的高度为 1.0.
的图
但是,当您设置 Normed=True
时,您将打开 规范化 。请注意,这与正态分布没有任何关系。查看 hist
的文档,您可以在此处找到:http://matplotlib.org/api/pyplot_api.html?highlight=hist#matplotlib.pyplot.hist
您会看到选项 Normed
的作用,即:
If True, the first element of the return tuple will be the counts normalized to form a probability density, i.e., n/(len(x)`dbin), i.e., the integral of the histogram will sum to 1. If stacked is also True, the sum of the histograms is normalized to 1.
所以它给了你公式。所以在你的情况下,你有三个点,即 len(x)=3。如果您查看绘图,您会发现 bin 的宽度为 0.2,因此 dbin=0.2。对于 1
、2
和 3
,每个值只出现一次,您将有 n=1。因此,条形图的高度应为 1/(3*0.2) = 1.67,这正是您在直方图中看到的。
现在对于正态分布,这只是一个特定的概率函数,定义为您给出的公式。它在许多领域都很有用,因为它与不确定性有关。例如,您会在统计数据中看到很多。 Wikipedia article on it 有很多信息。
如果要生成符合正态分布的值列表,我建议阅读 numpy.random.normal
的文档,它将为您完成此操作:https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html
我编写了这段代码来生成一组值 1,2,3 的正态分布:
import pandas as pd
import random
import numpy as np
df = pd.DataFrame({'col1':[1,2,3]})
print(df)
fig, ax = plt.subplots(1,1)
df.plot(kind='hist', normed=True, ax=ax)
Returns :
X 值是可能值的范围,但 Y 值是如何解释的?
读取 http://www.stat.yale.edu/Courses/1997-98/101/normal.htm Y 值使用以下方法计算:
A normal distribution has a bell-shaped density curve described by its mean and standard deviation . The density curve is symmetrical, centered about its mean, with its spread determined by its standard deviation. The height of a normal density curve at a given point x is given by
这个公式是什么意思?
我认为您在这里混淆了两个概念。直方图只会绘制某个值出现的次数。因此,对于 [1,2,3]
的列表,值 1
将出现一次并且 2
和 3
的值相同。如果你设置 Normed=False
你会得到你现在拥有的高度为 1.0.
但是,当您设置 Normed=True
时,您将打开 规范化 。请注意,这与正态分布没有任何关系。查看 hist
的文档,您可以在此处找到:http://matplotlib.org/api/pyplot_api.html?highlight=hist#matplotlib.pyplot.hist
您会看到选项 Normed
的作用,即:
If True, the first element of the return tuple will be the counts normalized to form a probability density, i.e., n/(len(x)`dbin), i.e., the integral of the histogram will sum to 1. If stacked is also True, the sum of the histograms is normalized to 1.
所以它给了你公式。所以在你的情况下,你有三个点,即 len(x)=3。如果您查看绘图,您会发现 bin 的宽度为 0.2,因此 dbin=0.2。对于 1
、2
和 3
,每个值只出现一次,您将有 n=1。因此,条形图的高度应为 1/(3*0.2) = 1.67,这正是您在直方图中看到的。
现在对于正态分布,这只是一个特定的概率函数,定义为您给出的公式。它在许多领域都很有用,因为它与不确定性有关。例如,您会在统计数据中看到很多。 Wikipedia article on it 有很多信息。
如果要生成符合正态分布的值列表,我建议阅读 numpy.random.normal
的文档,它将为您完成此操作:https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html