python - Python 相关矩阵 - 只需要绝对值大于 0.5 的列
问题描述
我有 41 个变量,其中大多数根本不相关。我只想包括几个列来说明更高相关或更高度负相关的列。尽我所能尝试,即使我查看了许多文章和问题,我似乎也无法让它发挥作用。谢谢你。
df.columns
Index(['ResponseId', 'Consent', 'AgeQualifier', 'Team', 'TeamOther', 'FanStrength', 'WinImportance', 'Emotion', 'Happiness', 'Satisfaction', 'Passion', 'ViewershipHomeGame' , 'ViewershipRoadGame', 'ViewershipTVCable', 'ViewershipStreaming', 'ViewershipRestaurantBar', 'NameChangeViewershipHomeGame', 'NameChangeViewershipRoadGame', 'NameChangeViewershipTVCable', 'NameChangeViewershipStreaming', 'NameChangeViewershipRestaurantBar', 'Purchased', 'Purchased_JerseyPuring_1', Purchased_Memorabilia_3'、'Purchased_Office_4'、'Purchased_Equipment_5'、'PurchaseIntentionNameChangeJersey'、'PurchaseIntentionNameChangeClothing'、'PurchaseIntentionNameChangeMemorabilia'、'PurchaseIntentionNameChangeHomeOffice'、'PurchaseIntentionNameChangeEquipment'、'Support_SeasonTickets'、'Support_Donations'、'Support_Volunteer'、'SupportNameChangeSeasonTickets'、'SupportNameChangeDonateMoney'、'SupportNameChangeVolunteer'、'AgeState'、' , '种族', 'EthnicityOther', '收入', '绘图', '电子邮件'], dtype='object')SupportNameChangeSeasonTickets'、'SupportNameChangeDonateMoney'、'SupportNameChangeVolunteer'、'State'、'Gender'、'Age'、'Ethnicity'、'EthnicityOther'、'Income'、'Drawing'、'Email']、dtype='object')SupportNameChangeSeasonTickets'、'SupportNameChangeDonateMoney'、'SupportNameChangeVolunteer'、'State'、'Gender'、'Age'、'Ethnicity'、'EthnicityOther'、'Income'、'Drawing'、'Email']、dtype='object')
相关矩阵 = df.corr().round(2)
无花果,ax = plt.subplots(figsize=(50,50)) sns.heatmap(data=correlation_matrix,cmap = 'rainbow' , annot=True, ax=ax)
想法?
解决方案
清洁后的矩阵将是
同意 | 年龄限定符 | 团队 | 粉丝力量 | 赢重要 | |
---|---|---|---|---|---|
同意 | 钠 | 钠 | 钠 | 钠 | 钠 |
年龄限定符 | 钠 | 1.0 | 钠 | 钠 | 钠 |
团队 | 钠 | 钠 | 1.00 | 0.02 | 0.02 |
粉丝力量 | 钠 | 钠 | 0.02 | 1.00 | 0.69 |
赢重要 | 钠 | 钠 | 0.02 | 0.69 | 1.00 |
要解决这个问题,您需要选择任何非对角矩阵值且绝对值 >0.5
temp = df[(df>0.5)&(df!=1)].abs().max()
print(temp[~temp.isna()])
这将产生在相关矩阵>0.5 中具有至少一个相关性的列名
这产生
FanStrength 0.69
WinImportance 0.69
dtype: float64
推荐阅读
- single-page-application - SPA AEM 中特定区域所需的动态标头体验片段
- php - 试图获取非对象的属性“id_pembelian”
- javascript - 如何使机器人加入机器人所在的所有服务器中的语音通道?
- typescript - Mongoose findByIdAndUpdate 不更新文档
- python - 如何向 Django 的默认用户模型添加另一个字段。例如,添加一个名为 matricule 的字段
- react-window - react-window-infinite-loader 在加载更多项目时滚动到顶部
- arrays - 将不同工作表中(满足条件)的列和标签名称过滤到 2 列中,没有空格
- reactjs - 来自 Uint8Array 的 ImageData 没有画布
- php - 使用 codeigniter 上的 htaccess 根据参数更改 url
- python - 在 python 中向所有人分享谷歌电子表格