美文网首页python数据
python进行pearson, spearman, kenda

python进行pearson, spearman, kenda

作者: MR来了 | 来源:发表于2021-04-26 11:44 被阅读0次

    背景

    网上提供了所谓的python代码实现都是有问题的,其中pvalue的计算是错误的!!!

    https://my.oschina.net/u/4344027/blog/3393685
    https://www.cnblogs.com/yjd_hycf_space/p/11537153.html
    

    正确的方法

    正确的方法是调用scipy这个包

    from scipy import stats
    dists1 = [0.2, 0.4, 0.3, 0.6, 0.9, 0.4]
    dists2 = [0.3, 0.3, 0.2, 0.7, 0.8, 0.3]
    
    ## pearson
    r, p = stats.pearsonr(dists1, dists2)
    print(r, p)
    
    ## spearman
    r, p = stats.spearmanr(dists1, dists2)
    print(r,p)
    
    ## kendall
    r, p = stats.kendalltau(dists1, dists2)
    print(r,p)
    

    相关文章

      网友评论

        本文标题:python进行pearson, spearman, kenda

        本文链接:https://www.haomeiwen.com/subject/zrpurltx.html