当特征不相关时,Pearson 相关性说明了什么

What does Pearson correlation tell when features are uncorrelated

我有一个数据集(31 个特征,包括 class)。此数据集将用于 class 化问题。我想使用 pandas 中存在的 Pearson 相关性来检查特征之间的相关性。当我设置 Pearson 的 threshold > 0.5 时,我得到以下信息:

import pandas as pd

data = pd.read_csv("../dataset.csv")
cor = data.corr(method='pearson')
cor_target = abs(cor['Class'])
result = cor_target[cor_target > 0.5]
print(result)

结果是:

Class    1.0
Name: Class, dtype: float64

事实证明,所有 30 特征根本不相关。这是什么意思?它总是一个很好的指标,表明特征是独立的吗?

谢谢。

你的假设有些错误。

举个例子:

import pandas as pd

data = pd.DataFrame({'a': [1, 2, 3, 4, 5], 'b': [1, 2, 3, 4, 5], 'Class' : [0, 1, 1, 0, 1]})
cor = data.corr(method='pearson')
print(cor)
cor_target = abs(cor['Class'])
print(cor_target)
result = cor_target[cor_target > 0.5]
print(result)
              a         b     Class
a      1.000000  1.000000  0.288675
b      1.000000  1.000000  0.288675
Class  0.288675  0.288675  1.000000
a        0.288675
b        0.288675
Class    1.000000
Name: Class, dtype: float64
Class    1.0
Name: Class, dtype: float64

特征集 ab 完全相同,它们具有 1.0 的相关性,但您仍然只会得到 1.

去除class标签,只观察中间特征之间的相关性

观察相关矩阵和select相关性低的矩阵。

import pandas as pd

data = pd.DataFrame({'a': [1, 2, 3, 4, 5], 'b': [1, 2, 3, 4, 5], 'Class' : [0, 1, 1, 0, 1]})
cor = data[['a', 'b']].corr(method='pearson')
print(cor)
cor_target = abs(cor)

     a    b
a  1.0  1.0
b  1.0  1.0

如果你想使用标签,试试scikit-learn的特征重要性,https://scikit-learn.org/stable/modules/feature_selection.html