首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >KSTest TypeError:_parse_args()从3到5个位置参数,但给出了6个

KSTest TypeError:_parse_args()从3到5个位置参数,但给出了6个
EN

Stack Overflow用户
提问于 2018-08-08 06:55:22
回答 1查看 1.1K关注 0票数 0

我试图得到我所拥有的一组值的最佳拟合分布。我想出了下面的函数来实现这个功能。

代码语言:javascript
运行
复制
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文档,一切都应该是好的。但这会产生以下错误。

代码语言:javascript
运行
复制
TypeError: _parse_args() takes from 3 to 5 positional arguments but 6 were given

这是什么原因?

下一行将导致此错误。

代码语言:javascript
运行
复制
D, p = st.kstest(data, dist_name, args=param)

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-08 08:12:31

通过以下修改解决问题。

代码语言:javascript
运行
复制
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]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51740306

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档