Python统计数据分析教程:正态分布值的数学计算
正态分布是通过排列数据中每个值的概率分布来表示数据的一种形式。大多数值都保持在平均值附近,因此排列是对称的。
可以使用 numpy 库中的各种函数以数学方式计算正态分布值。通过绘制概率分布曲线来创建直方图。
import matplotlib.pyplot as plt
import numpy as np
mu, sigma = 0.5, 0.1
s = np.random.normal(mu, sigma, 1000)
# Create the bins and histogram
count, bins, ignored = plt.hist(s, 20, normed=True)
# Plot the distribution curve
plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *
np.exp( - (bins - mu)**2 / (2 * sigma**2) ), linewidth=3, color='y')
plt.show()
Python运行上面的代码示例,得到以下结果 -
版权声明
本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。