高斯分布,也叫正態分布,是一個在數學、物理及工程等領域都非常重要的概率分布,在統計學的許多方面有着重大的影響力。
若隨機變量X服從一個數學期望為μ、方差為σ^2的正態分布,記為N(μ,σ^2)。其概率密度函數為正態分布的期望值μ決定了其位置,其標准差σ決定了分布的寬度。當μ = 0,σ = 1時的正態分布是標准正態分布。
定義
---------以上摘自百度百科
import numpy as np import matplotlib.pyplot as plt import math def normal_distribution(x, mean, sigma): return np.exp(-1*((x-mean)**2)/(2*(sigma**2)))/(math.sqrt(2*np.pi) * sigma) mean1, sigma1 = 0, 1 x1 = np.linspace(mean1 - 6*sigma1, mean1 + 6*sigma1, 100) mean2, sigma2 = 0, 2 x2 = np.linspace(mean2 - 6*sigma2, mean2 + 6*sigma2, 100) mean3, sigma3 = 5, 1 x3 = np.linspace(mean3 - 6*sigma3, mean3 + 6*sigma3, 100) y1 = normal_distribution(x1, mean1, sigma1) y2 = normal_distribution(x2, mean2, sigma2) y3 = normal_distribution(x3, mean3, sigma3) plt.plot(x1, y1, 'r', label='m=0,sig=1') plt.plot(x2, y2, 'g', label='m=0,sig=2') plt.plot(x3, y3, 'b', label='m=1,sig=1') plt.legend() plt.grid() plt.show()