Friday, June 3, 2022

AI/ML: seaborn heat map correlation between dependent and independent variables

What we often want to create, is a colored map that shows the strength of the correlation between every independent variable that we want to include in our model and the dependent variable.

The following code returns the correlation of all features with ‘Sale Price’, a single, dependent variable, sorted by ‘Sale Price’ in a descending manner.

dataframe.corr()[['Sale Price']].sort_values(by='Sale Price', ascending=False)

plt.figure(figsize=(8, 12))

heatmap = sns.heatmap(dataframe.corr()[['Sale Price']].sort_values(by='Sale Price', ascending=False), vmin=-1, vmax=1, annot=True, cmap='BrBG')

heatmap.set_title('Features Correlating with Sales Price', fontdict={'fontsize':18}, pad=16);

references:

https://medium.com/@szabo.bibor/how-to-create-a-seaborn-correlation-heatmap-in-python-834c0686b88e

No comments:

Post a Comment