距離相關系數以及python包的安裝
覺得有用的話,歡迎一起討論相互學習~
版權聲明:本文為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
如果有其他需要補充的和寫得不足的地方歡迎各位補充!




