Python Scipy KSTest TypeError:_parse_args()接受3到5个位置参数,但给出了6个

Python Scipy KSTest TypeError:_parse_args()接受3到5个位置参数,但给出了6个,python,scipy,Python,Scipy,我试图得到我所拥有的一组值的最佳拟合分布。我提出了以下函数来实现这一点 def get_best_distribution(data): dist_names = [st.exponweib, st.weibull_max, st.weibull_min,st.pareto, st.genextreme] dist_results = [] params = {} for dist_name in dist_names: dist = dist_n

我试图得到我所拥有的一组值的最佳拟合分布。我提出了以下函数来实现这一点

def get_best_distribution(data):
    dist_names = [st.exponweib, st.weibull_max, st.weibull_min,st.pareto, st.genextreme]
    dist_results = []
    params = {}
    for dist_name in dist_names:
        dist = dist_name
        param = dist.fit(data)

        params[dist_name] = param
        # Applying the Kolmogorov-Smirnov test
        D, p = st.kstest(data, dist_name, args=param)
        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: "+st(best_dist))
    print("Best p value: "+ str(p))
    print("Parameters for the best fit: "+ str(params[best_dist]))

    return best_dist, best_p, params[best_dist]
根据Scipy文档,一切都应该正常。但这会产生以下错误

TypeError: _parse_args() takes from 3 to 5 positional arguments but 6 were given
这是什么原因

以下行导致此错误

D, p = st.kstest(data, dist_name, args=param)

谢谢

使用以下修改解决了问题

def get_best_distribution(data):
    dist_names = ["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(p))
    print("Parameters for the best fit: "+ str(params[best_dist]))

    return best_dist, best_p, params[best_dist]

您可以进行一些调试。将
dist_name
缩减为一个分布(选择一个)。错误是否仍然发生?是。是的。这是导致错误的行。D、 p=st.kstest(数据,dist_名称,args=param)