Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中的离散发行版之间进行选择_Python_Python 3.x_Scipy_Statistics_Distribution - Fatal编程技术网

在python中的离散发行版之间进行选择

在python中的离散发行版之间进行选择,python,python-3.x,scipy,statistics,distribution,Python,Python 3.x,Scipy,Statistics,Distribution,我试图在离散分布之间选择最佳拟合,但我得到一个错误,即离散分布没有属性拟合。有人知道如何解决这个问题,或者有其他方法在离散分布中进行选择吗 import scipy.stats as st def get_best_distribution(data): dist_names = ["bernoulli", "poisson", "binom", "geom", "logser", &qu

我试图在离散分布之间选择最佳拟合,但我得到一个错误,即离散分布没有属性拟合。有人知道如何解决这个问题,或者有其他方法在离散分布中进行选择吗

import scipy.stats as st
def get_best_distribution(data):
    dist_names = ["bernoulli", "poisson", "binom", "geom", "logser", "randint"]
    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]
print(get_best_distribution(df)

AttributeError: 'bernoulli_gen' object has no attribute 'fit'

SciPy
中只能拟合连续分布。离散分布和多元分布不支持此功能。

谢谢。在python中,有没有等效的方法来选择离散发行版?@uni13,我不太了解统计数据,无法猜测为什么不为离散发行版实现精确拟合。但我认为出于某种原因,您必须手动查找发行版的参数。您可以构造一个。