【问题标题】:Best way to do correlation analysis of data which is 1 or 0 python对 1 或 0 python 的数据进行相关性分析的最佳方法
【发布时间】:2021-12-11 18:06:26
【问题描述】:

我有这个示例数据

point_1 = [1,1,1,1,1,1,1,1,1,0,0,1]
point_2 = [1,1,1,1,1,1,1,1,0,1,0,1]
point_3 = [1,1,1,1,1,1,1,1,1,1,0,1]
values =  [1900,1700,1800,1300,1600,1400,1900,1300,1800,1400,900,1200]

dataframe = pd.DataFrame({'point_1': [1,1,1,1,1,1,1,1,1,0,0,1],
                         'point_2': [1,1,1,1,1,1,1,1,0,1,0,1],
                         'point_3': [1,1,1,1,1,1,1,1,1,1,0,1],
                         'values':  [1900,1700,1800,1300,1600,1400,1900,1300,1800,1400,900,1200]})

import seaborn as sns
sns.heatmap(dataframe.corr())

找到它们之间关系的好方法是什么? 我尝试了一个相关图,但它并没有给我太多的洞察力。请让我知道您对我可以尝试什么的想法。

【问题讨论】:

  • 您对示例数据的预期结果(或洞察力)是什么?
  • 了解值是否受到 3 点的影响以及是否有任何方法或查看它是否例如一个点是 1,其他点是 0 那么这是否意味着值会更低或更高,例如

标签: python numpy correlation


【解决方案1】:

导入库

from collections import defaultdict
from sklearn.preprocessing import LabelEncoder
import seaborn as sns
import matplotlib.pyplot as plt
import warnings

d = defaultdict(LabelEncoder)

df_temp=dataframe.astype(str) #read in object format

fit = df_temp.apply(lambda x: d[x.name].fit_transform(x))

corr = fit.corr()

corr['total_amounts'].sort_values(ascending=False)
plt.figure(figsize=(25,10))
sns.heatmap(corr,annot=True,cmap='coolwarm')

https://i.stack.imgur.com/zedNK.png #you can see the image here.
![](https://i.stack.imgur.com/zedNK.png) #i don't know how to display the image

corr['values'] #here you can see positive and negative corr. 
#you may ignore most neg. in original dataframe for further decision making such as regression testing or training purposes

point_1   -0.201688
point_2   -0.504219
point_3   -0.475923
values     1.000000



【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-10
    • 2015-12-29
    • 1970-01-01
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多