Correlations with a Heatmap#

Importing libraries and packages#

 1# Mathematical operations and data manipulation
 2import pandas as pd
 3
 4# Visualisation
 5import seaborn as sns
 6import matplotlib.pyplot as plt
 7
 8# Warnings
 9import warnings
10
11warnings.filterwarnings("ignore")
12
13%matplotlib inline

Set paths#

1# Path to datasets directory
2data_path = "./datasets"
3# Path to assets directory (for saving results to)
4assets_path = "./assets"

Loading dataset#

1# load data
2dataset = pd.read_csv(f"{data_path}/preprocessed_heart.csv")
3dataset.head().T
0 1 2 3 4
age 63.0 37.0 41.0 56.0 57.0
sex 1.0 1.0 0.0 1.0 0.0
chest_pain 3.0 2.0 1.0 1.0 0.0
rest_bp 145.0 130.0 130.0 120.0 120.0
chol 233.0 250.0 204.0 236.0 354.0
fast_bld_sugar 1.0 0.0 0.0 0.0 0.0
rest_ecg 0.0 1.0 0.0 1.0 1.0
max_hr 150.0 187.0 172.0 178.0 163.0
ex_angina 0.0 0.0 0.0 0.0 1.0
st_depr 2.3 3.5 1.4 0.8 0.6
slope 0.0 0.0 2.0 2.0 2.0
colored_vessels 0.0 0.0 0.0 0.0 0.0
thalassemia 1.0 2.0 2.0 2.0 2.0
target 1.0 1.0 1.0 1.0 1.0

Correlations with a Heatmap#

1f, ax = plt.subplots(figsize=(12, 12))
2sns.heatmap(dataset.corr(), annot=True, linewidths=0.5, fmt=".1f", ax=ax)
3plt.show()
../../_images/085707ca7cf5d94b79115e2f9000c9cf9859bd84e3bc42538fea95cea41d3268.png