我正在尝试对一组数据进行许多不同分布的KSI测试。我要执行的测试可以在此处的堆栈溢出问题中找到:
How to find probability distribution and parameters for real data? (Python 3)
不幸的是,当我尝试将“ truncnorm”添加到要尝试的分布列表中时,代码无法找到截断正态分布的参数和p值。 P值始终为零。
有人可以帮我吗?
谢谢!
$query
当我尝试运行时:
print('Getting Best Fit')
def get_best_distribution(data):
dist_names = ["norm", "truncnorm", "exponweib", "weibull_max", "weibull_min", "pareto", "genextreme"]
dist_results = []
params = {}
for dist_name in dist_names:
dist = getattr(stats, dist_name)
param = dist.fit(data)
params[dist_name] = param
# Applying the Kolmogorov-Smirnov test
D, p = stats.kstest(data, dist_name, args=param)
print("p value for "+dist_name+" = "+str(p))
dist_results.append((dist_name, p))
# select the best fitted distribution
best_dist, best_p = (max(dist_results, key=lambda item: item[1]))
if math.isnan(best_p) == True:
print('skipping')
return 'None', 'None', 'None'
# store the name of the best fit and its p value
else:
print("Best fitting distribution: "+str(best_dist))
print("Best p value: "+ str(best_p))
print("Parameters for the best fit: "+ str(params[best_dist]))
print('\n')
return best_dist, best_p, params[best_dist]
我得到:
param = dist.fit(data)