使用pandas中的皮尔逊,肯德尔和斯皮尔曼做特征相关性分析
三种系数的具体试用范围可参考: https://blog.csdn.net/qrdsy_lrf/article/details/79227969
import pandas as pd
from settings import colss
def corr_matrix(df):
"""
返回与标签列有关的相关性矩阵
:param dataset_name:
:param label:
:return:
"""
pearson = df.corr(method='pearson')
print(pearson)
print('-----------------------------------------------')
kendall = df.corr(method='kendall')
print(kendall)
print('-----------------------------------------------')
spearman = df.corr(method='spearman')
print(spearman)
if __name__ == '__main__':
df = pd.read_csv(r'F:\Users\Administrator\Desktop\11_viewer\file_storage\S7\S7数据测试.csv')[colss['AirBoxPres']]
corr_matrix(df=df)
三种系数的执行结果分别如下
AmbientPres ServoLevel Throttle SetPres AirBoxPres
AmbientPres 1.000000 -0.723157 -0.362301 -0.040379 0.443553
ServoLevel -0.723157 1.000000 -0.158969 -0.242736 -0.683768
Throttle -0.362301 -0.158969 1.000000 0.797434 0.615427
SetPres -0.040379 -0.242736 0.797434 1.000000 0.636150
AirBoxPres 0.443553 -0.683768 0.615427 0.636150 1.000000
-----------------------------------------------
AmbientPres ServoLevel Throttle SetPres AirBoxPres
AmbientPres 1.000000 -0.577694 -0.002187 -0.015900 0.251817
ServoLevel -0.577694 1.000000 -0.074581 -0.124946 -0.243473
Throttle -0.002187 -0.074581 1.000000 0.867175 0.239200
SetPres -0.015900 -0.124946 0.867175 1.000000 0.249051
AirBoxPres 0.251817 -0.243473 0.239200 0.249051 1.000000
-----------------------------------------------
AmbientPres ServoLevel Throttle SetPres AirBoxPres
AmbientPres 1.000000 -0.332931 -0.041303 -0.010988 0.410620
ServoLevel -0.332931 1.000000 -0.149809 -0.160319 -0.304079
Throttle -0.041303 -0.149809 1.000000 0.976620 0.389274
SetPres -0.010988 -0.160319 0.976620 1.000000 0.376923
AirBoxPres 0.410620 -0.304079 0.389274 0.376923 1.000000