scipy.stats.distributions.fit如何工作?

问题描述

我试图用普通的近似估计一些硬分布。但是scipy.stats.norm.fit给出了一些尴尬的结果。近似结果与原始结果相差很远。然后,我尝试手动设置参数,它看起来要好得多。但是,根据对数似然状态,则metod更好。 为什么?一切正常吗?还有其他估算分布参数的方法吗?

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
domain = np.linspace(0,1,100)
import math


def f(x):
    return 100 / 0.5 * 0.5 ** 50 / (math.factorial(49)) * (100 *x / 0.5) ** 49 * np.exp(-(100 * x / 0.5 ) / 2)

data = [f(x) for x in domain]
plt.plot(domain,data,label = 'orig')

params = norm.fit(data)
plt.plot(domain,norm.pdf(domain,*params),label = 'approx_fit')
plt.plot(domain,0.495,0.07),label = 'approx_manual')

plt.legend()
plt.show()
print(f'LLH by fitting with scipy.stats.norm.fit : {norm.logpdf(data,*params).sum()}')
new_params = (0.495,0.07)
print(f'LLH by manually founded parameters : {norm.logpdf(data,*new_params).sum()}')

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)