Variable correlation heat map

In order to avoid multicollinearity when modeling, we generally analyze the correlation between variables. To measure the correlation of variables, we generally calculate the Pearson correlation coefficient between the variables. In order to better show the correlation between variables, the following introduces how to use a heat map to express the correlation between variables.

def corr_map(df):
    var_corr = df.corr()
    mask = np.zeros_like(var_corr, dtype=np.bool)
    mask[np.triu_indices_from(mask)] = True
    cmap = sns.diverging_palette(220, 10, as_cmap=True)
    f, ax = plt.subplots(figsize=(20, 12))
    sns.set(font_scale=1)
    sns.heatmap(var_corr, mask=mask, cmap=cmap, vmax=1, center=0
               ,square=True, linewidths=.5, cbar_kws={"shrink": .5}
               ,annot=True,annot_kws={'size':12,'weight':'bold', 'color':'red'})
    plt.show()   

The effect is as follows:

Guess you like

Origin blog.csdn.net/lz_peter/article/details/89278874