我检查了EES,感觉应该是正确的,但是输出的数字太奇怪了。我希望有一个人可以帮助我。 我对Python和统计资料非常陌生。我不知道这是否正常,但是使用matlab的相同数据结果似乎还可以。
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import scipy.stats as st
import seaborn as sns
import numpy as np
data = [ 40, 21, 14, 9, 14, 32, 28, 42, 33, 30, 40, 14, 11, 32,
53, 163, 28, 13, 14, 15, 16, 15, 12, 9, 12, 21, 41, 24,
12, 26, 14, 36, 22, 4, 36, 13, 71, 10, 30, 17, 89, 31,
30, 13, 37, 22, 30, 32, 31, 20, 19, 53, 18, 30, 31, 11,
39, 37, 12, 26, 9, 9,]
sns.set()
DISTRIBUTIONS = [st.norm,st.gamma,st.weibull_min,st.burr,st.beta]
bins_=20
def cal_sse(fitting,data,bins):
y, x = np.histogram(data , bins=bins)
bin_width = x[1]-x[0]
x_mid = (x + np.roll(x, -1))[:-1] / 2.0
N = len(data)
params = fitting.fit(data)
arg = params[:-2]
loc = params[-2]
scale = params[-1]
pdf = fitting.pdf(x_mid, loc=loc, scale=scale, *arg)
pdf_scaled = pdf * bin_width * N
sse = np.sum((y - pdf_scaled)**2)
if fitting == st.weibull_min:
print(y,x)
print('------------------')
print(pdf_scaled )
return sse
def draw_fitting(data,bins,fittings):
for fit in range(len(fittings)):
if fit == 0:
sns.distplot(data,bins=bins, kde=False, fit=fittings[fit],fit_kws={"color": "g", "linewidth": 3,"dashes":[6, 2]})
print(cal_sse(fittings[fit],data,bins))
else:
sns.distplot(data,bins=bins, kde=False ,fit=fittings[fit],hist_kws={"alpha":0})
print(cal_sse(fittings[fit],data,bins))
draw_fitting(data,bins_,DISTRIBUTIONS)
plt.show()