zoukankan      html  css  js  c++  java
  • 【转】距离相关系数以及python包的安装

    距离相关系数以及python包的安装

    觉得有用的话,欢迎一起讨论相互学习~

    我的微博我的github我的B站

    版权声明:本文为CSDN博主「 LUC 」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/weixin_45456209/article/details/108356586

    距离相关系数:研究两个变量之间的独立性,距离相关系数为0表示两个变量是独立的。克服了皮尔逊相关系数(Pearson)的弱点。pearson相关系数为0并不一定表示两个变量之间是独立的,也有可能是非线性相关的。

    python实现:

    1.安装dcor包

    pip install dcor
    

    安装的时候可能会遇到 报错:ERROR: Cannot uninstall 'llvmlite'. It is a distutils installed project.

    解决方法参考:https://blog.csdn.net/weixin_43535207/article/details/104385743

    2.使用方法:

    import numpy as np
    a1=np.array([11,2,56,34])
    b1=np.array([45,15,26,24])
    dcor.distance_correlation(a1,b1)
    

    out: 0.6673874262718296

    这里计算的变量得是array形式,需要使用shape。如果是list则可以转换成array形式进行计算:

    import numpy as np
    a=[11,2,56,34]
    b=[45,15,26,24]
    a1=np.array(a)
    b1=np.array(b)
    dcor.distance_correlation(a1,b1)
    

    网上关于dcor包的资料并不多,在网上查找了很多资料才终于把距离相关系数实现出来,关于dcor包更多详细的介绍访问:https://dcor.readthedocs.io/en/latest/modules/dcor._dcor.html#b-distance-correlation

    References

    BCH19
    Arin Chaudhuri and Wenhao Hu. A fast algorithm for computing distance correlation. Computational Statistics & Data Analysis, 135:15–24, July 2019. doi:10.1016/j.csda.2019.01.016.

    BHS16
    Xiaoming Huo and Gábor J. Székely. Fast computing for distance covariance. Technometrics, 58(4):435–447, 2016. URL: http://dx.doi.org/10.1080/00401706.2015.1054435, arXiv:http://dx.doi.org/10.1080/00401706.2015.1054435, doi:10.1080/00401706.2015.1054435.

    BSRB07
    Gábor J. Székely, Maria L. Rizzo, and Nail K. Bakirov. Measuring and testing dependence by correlation of distances. The Annals of Statistics, 35(6):2769–2794, 12 2007. URL: http://dx.doi.org/10.1214/009053607000000505, doi:10.1214/009053607000000505.

    在网上有一个自定义距离相关系数函数的代码:https://gist.github.com/satra/aa3d19a12b74e9ab7941

    其中numbapro没有这个包,把numbapro改为numba就好了。

    from numba import jit, float32
    

    如果有其他需要补充的和写得不足的地方欢迎各位补充!

  • 相关阅读:
    Day 69
    Day 68
    Day 67
    Day 66
    Day 65
    Day 64
    Day 63
    Day 62
    Day 61
    Day 60
  • 原文地址:https://www.cnblogs.com/cloud-ken/p/15516754.html
Copyright © 2011-2022 走看看