【问题标题】:How do I estimate the right parameters for a cumulative gaussian fit?如何估计累积高斯拟合的正确参数?
【发布时间】:2016-07-21 04:46:57
【问题描述】:

我正在尝试将累积高斯分布拟合到我的数据中,但是拟合显然是错误的。为什么我得到错误的均值和标准差?您可以在下面找到我的代码和输出。

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()

输出:

【问题讨论】:

    标签: python numpy curve-fitting gaussian


    【解决方案1】:

    目前,您所做的任何事情都不会告诉系统您正在尝试拟合 累积高斯。 norm.fit(Pn_final)Pn_final 代表 高斯 的假设下正在尽力而为。

    一种方法是使用scipy.optimize.curve_fit,然后添加

    from scipy.optimize import curve_fit
    
    mu1,sigma1 = curve_fit(norm.cdf, testrefratios, Pn_final, p0=[0,1])[0]
    ax.plot(t, norm.cdf(t, mu1, sigma1), alpha=.5)
    
    mu1,sigma1 = curve_fit(norm.cdf, testrefratios, Pd_final, p0=[0,1])[0]
    ax.plot(t, norm.cdf(t, mu1, sigma1), alpha=.5)
    

    给我

    至少看起来更可信。

    【讨论】:

    • 这会将 Pn_finalPd_final 值视为经验 cdf 值,对吧?
    猜你喜欢
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 2019-12-19
    • 2015-12-09
    • 2015-10-16
    • 1970-01-01
    相关资源
    最近更新 更多