text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

csv_path = '/kaggle/input/heart-failure-prediction/heart.csv'
hrz = pd.read_csv(csv_path)

target = ['HeartDisease']
num_attribs = ['Age', 'RestingBP', 'Cholesterol', 'MaxHR', 'Oldpeak']
cat_nom_attribs = ['ChestPainType', 'RestingECG', 'ST_Slope']
cat_bin_attribs = ['Sex', 'FastingBS', 'ExerciseAngina']
cat_attribs = cat_nom_attribs + cat_bin_attribs

attribs = num_attribs + target

ncol = 3
nrow = int(np.ceil(len(num_attribs) / ncol))
fig, axs = plt.subplots(nrow, ncol, figsize=(10, 5), facecolor=None)
i = 1
for col in num_attribs:
    plt.subplot(nrow, ncol, i)
    ax = sns.histplot(data=hrz, x=col, hue=target[0], multiple='stack', palette='colorblind')
    ax.set_xlabel(col, fontsize=12)
    ax.set_ylabel('count', fontsize=12)
    sns.despine(right=True)
    sns.despine(offset=0, trim=False)
    i += 1
fig.delaxes(axs[nrow - 1, ncol - 1])
plt.suptitle('Distribution of Numerical Features', fontsize=14)
plt.tight_layout()