对1或0 python数据进行相关性分析的最佳方法



我有这个示例data

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())

找到它们之间关系的好方法是什么?我试过一个相关图,但它并没有给我太多的启示。请让我知道你的想法,我可以尝试什么。

导入库

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

相关内容

  • 没有找到相关文章

最新更新