pandas相关性分析 您所在的位置:网站首页 pandas相关性分析 pandas相关性分析

pandas相关性分析

2023-03-10 08:44| 来源: 网络整理| 查看: 265

DataFrame.corr(method='pearson', min_periods=1)

参数说明:

method:可选值为{‘pearson’, ‘kendall’, ‘spearman’}

               pearson:Pearson相关系数来衡量两个数据集合是否在一条线上面,即针对线性数据的相关系数计算,针对非线性                                           数据便会有误差。

                kendall:用于反映分类变量相关性的指标,即针对无序序列的相关系数,非正太分布的数据

                spearman:非线性的,非正太分析的数据的相关系数

min_periods:样本最少的数据量

返回值:各类型之间的相关系数DataFrame表格。

为区分不同参数之间的区别,我们实验如下:

from pandas import DataFrame import pandas as pd x=[a for a in range(100)] #构造一元二次方程,非线性关系 def y_x(x): return 2*x**2+4 y=[y_x(i) for i in x] data=DataFrame({'x':x,'y':y}) #查看下data的数据结构 data.head() Out[34]: x y 0 0 4 1 1 6 2 2 12 3 3 22 4 4 36 data.corr() Out[35]: x y x 1.000000 0.967736 y 0.967736 1.000000 data.corr(method='spearman') Out[36]: x y x 1.0 1.0 y 1.0 1.0 data.corr(method='kendall') Out[37]: x y x 1.0 1.0 y 1.0 1.0

因为y经由函数构造出来,x和y的相关系数为1,但从实验结构可知pearson系数,针对非线性数据有一定的误差。

转自:https://blog.csdn.net/walking_visitor/article/details/85128461



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有