Menu

Visualizing Correlations Using a Heatmap

Visualizing Correlations Using a Heatmap

Correlation matrices become easier to interpret when visualized as heatmaps.

Code

**plt.figure(figsize=(10,8))**

**sns.heatmap(**

**correlation,**

**cbar=True,**

**square=True,**

**fmt=".1f",**

**annot=True,**

**annot_kws={"size":8},**

**cmap="Blues"**

**)**

Explanation

The heatmap uses colors to represent correlation strength.

Darker colors indicate stronger relationships.

The diagonal values are always equal to 1 because each variable is perfectly correlated with itself.

Heatmaps make it easier to identify:

  • Strong positive correlations
  • Strong negative correlations
  • Important predictors of house prices