相关疑难解决方法(0)

绘制一个奇特的对角相关矩阵,其系数位于上三角形中

我有以下合成数据框,包括数字列分类列以及label列。我想绘制一个对角相关矩阵并在上部显示相关系数,如下所示:

预期输出

图像

尽管合成数据集/数据帧中的分类列df需要转换为数值,但到目前为止,我已经使用了这个使用数据集的seaborn示例'titanic',该数据集是合成的并且适合我的任务,但我添加了label列,如下所示:

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="white")

# Generate a large random dataset with synthetic nature (categorical + numerical)
data = sns.load_dataset("titanic")
df = pd.DataFrame(data=data)

# Generate label column randomly '0' or '1'
df['label'] = np.random.randint(0,2, size=len(df))

# Compute the correlation matrix
corr = df.corr()

# Generate a mask for the …
Run Code Online (Sandbox Code Playgroud)

python r heatmap rpy2 seaborn

10
推荐指数
1
解决办法
2837
查看次数

标签 统计

heatmap ×1

python ×1

r ×1

rpy2 ×1

seaborn ×1