使用这种方法
import scipy.stats as st
def get_best_distribution(data):
dist_names = ["norm", "exponweib", "weibull_max", "weibull_min", "pareto", "genextreme"]
dist_results = []
params = {}
for dist_name in dist_names:
dist = getattr(st, dist_name)
param = dist.fit(data)
params[dist_name] = param
# Applying the Kolmogorov-Smirnov test
D, p = st.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]))
# store the name of the best fit and its p value
print("Best fitting distribution: "+str(best_dist))
print("Best p value: "+ str(best_p))
print("Parameters for the best fit: "+ str(params[best_dist]))
return best_dist, best_p, params[best_dist]
0
我有一个来自
sklearn
的数据集,并绘制了load_diabetes.target
数据的分布图(即,load_diabetes.data
用于预测的回归值)。我使用它是因为它具有回归
sklearn.datasets
的变量/属性最少的数量。使用Python 3, 如何获得最相似的分布类型和分布参数?
我所知道的
target
都是正的和偏斜的(正偏斜/右偏斜)。 。 。 Python中是否有办法提供一些分布,然后最适合target
数据/向量?或者,根据给出的数据实际建议适合度?对于那些具有理论统计知识但很少将其应用于“真实数据”的经验的人来说,这将是非常有用的。好处使用这种方法来找出“真实数据”的后验分布会有意义吗?如果没有,为什么不呢?