【问题标题】:Correlation among features特征之间的相关性
【发布时间】:2020-01-29 02:31:12
【问题描述】:

我在python中有以下问题:

我想在一个特征上打印多个特征的相关性

代码:

correlation=example.corr().abs()
correlation_lower=correlation('Volume')
my_feature=correlation_lower[correlatio_lower<0.9]

然后我将结果转换为 DataFrame 并将列命名为 Feature:

my_features=pd.DataFrame(my_feature)
my_feature['Feature']=my_feature.index

所以我现在有一个数据框,其中包含我的特征,即变量“Volume”的相关性。

现在我想检查相关性小于 0.9 的那些特征,并检查它们之间的相关性。 我用for循环试过了,但这不起作用:

for my_feature['Feature'] in example:
        print(example_corr())

最后,我想知道那些特征的名称,它们的相关性低于 0.9 的体积,并且彼此之间没有相关性。

我该怎么做?

【问题讨论】:

    标签: python correlation


    【解决方案1】:

    据我了解您的问题,您需要相关值(与音量)小于 0.9 的特征列表。

    corrmat =  example.corr()
    print(list(corrmat[(corrmat["Volume"]<0.9)]["Volume"].index.values))
    

    编辑:

    阅读您的评论后,我认为这可能对您有用:

    corrmat=train_df.corr()
    select_fet = set(list(corrmat[(corrmat["Volume"]<0.9)].index.values))
    corrmat = corrmat[(corrmat["Volume"]<0.9)].transpose()
    for i in corrmat:
        select_fet = select_fet.intersection(set(corrmat[(corrmat[i]<0.9)].index.values))
    print(select_fet)
    

    【讨论】:

    • 嗨,我已经这样做了。我现在要做的是获取相关性小于 0.9 的特征,检查这些特征之间的相关性并剔除相关的特征。例如:特征 a、b、c 和 d 的相关性小于 0.9。现在我想检查 a 和 b、a 和 c 等之间的相关性,并剔除那些相互关联的特征。最后,我只剩下例如a,c和d
    • 我已经编辑了我的答案,希望它能解决你的问题。
    • 非常感谢。不幸的是,我只得到 set() 作为输出。有没有办法为> 0,9的特征打印相关矩阵?因为对于 cormat,我知道行作为特征 >0.9 的相关矩阵,但列包含所有特征
    猜你喜欢
    • 2019-03-09
    • 2018-05-20
    • 2019-12-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多