pandas相关性分析的三种方法

使用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
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值