我试图将累积高斯分布拟合到我的数据中,但是拟合显然是错误的。为什么我得到了错误的均值和标准差?下面是我的代码和输出。在
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
testrefratios=np.array([ 0.2, 0.4, 0.6, 0.8, 0.9, 1. , 1.1, 1.2, 1.4, 1.6, 1.8])
Pn_final=np.array([ 0. , 0. , 0.03 , 0.35 , 0.47, 0.57 , 0.68, 0.73, 0.76 , 0.85 , 0.91])
Pd_final=np.array([ 0. , 0.03, 0.36 , 0.85 , 0.97, 0.98 , 0.98 , 0.99 , 1., 1., 1. ])
# cumulative gaussian fit
fg = plt.figure(1); fg.clf()
ax = fg.add_subplot(1, 1, 1)
t = np.linspace(0,2, 1000)
ax.grid(True)
ax.set_ylabel("Cumulative Probability Density")
ax.set_title("Fit to Normal Distribution")
mu1,sigma1 = norm.fit(Pn_final) # classical fit
ax.plot(t, norm.cdf(t, mu1, sigma1), alpha=.5)
mu1,sigma1 = norm.fit(Pd_final) # classical fit
ax.plot(t, norm.cdf(t, mu1, sigma1), alpha=.5)
ax.plot(testrefratios, Pn_final, 'bo',label='numerosity comparison')
ax.plot(testrefratios, Pd_final, 'ro', label='density comparison')
plt.legend(loc='lower right')
fg.canvas.draw()
输出:
目前,你所做的一切都不是告诉系统你在试图拟合一个累积高斯分布。}代表一个高斯的假设下发挥了最大的作用。在
norm.fit(Pn_final)
在假设{一种方法是使用
scipy.optimize.curve_fit
,然后添加给了我
至少看起来更可信。在
相关问题 更多 >
编程相关推荐