B 4 Heart
B 4 Heart
In [2]: df = pd.read_csv('heart.csv')
Out[3]: age sex cp trtbps chol fbs restecg thalachh exng oldpeak slp caa thall output
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
In [4]: df = df.drop_duplicates()
In [5]: df
Out[5]: age sex cp trtbps chol fbs restecg thalachh exng oldpeak slp caa thall output
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
Duplicates removed
In [6]: df.isna().sum()
# No null values, it's clean
age 0
Out[6]:
sex 0
cp 0
trtbps 0
chol 0
fbs 0
restecg 0
thalachh 0
exng 0
oldpeak 0
slp 0
caa 0
thall 0
output 0
dtype: int64
Plots
In [7]: import seaborn as sns
import matplotlib.pyplot as plt
In [8]: df.columns
In [9]: plt.figure(figsize=(10,6))
sns.heatmap(df.corr(),cmap = 'YlGnBu', annot = True)
Line chart
In [10]: sns.lineplot(data=df,x=df.age,y=df.cp,hue='output')
In [11]: sns.lineplot(data=df,x=df.age,y=df.trtbps,hue='output')
In [12]: sns.lineplot(data=df,x=df.age,y=df.chol,hue='output')
In [13]: sns.lineplot(df,x=df.oldpeak,y=df.exng,hue='output')
In [14]: # Shows the Distribution of Heat Diseases with respect to male and female
sns.histplot(data=df,
x=df.output,
hue=df.sex)
In [15]: # Shows the Distribution of cp types with respect to male and female
sns.histplot(data=df,
C:\Users\Admin\anaconda3\Lib\site-packages\seaborn\axisgrid.py:118: UserWarning: T
he figure layout has changed to tight
self._figure.tight_layout(*args, **kwargs)
C:\Users\Admin\AppData\Local\Temp\ipykernel_13800\1194111231.py:6: UserWarning: Th
e figure layout has changed to tight
plt.tight_layout()
[]
Out[19]:
<Figure size 1500x1000 with 0 Axes>
In [20]: plt.figure(figsize=(15,10))
for i,col in enumerate(temp_df.columns,1):
plt.subplot(4,3,i)
plt.title(f"Distribution of {col} Data")
sns.histplot(df[col],kde=True)
plt.tight_layout()
plt.plot()
C:\Users\Admin\AppData\Local\Temp\ipykernel_13800\4266913939.py:6: UserWarning: Th
e figure layout has changed to tight
plt.tight_layout()
C:\Users\Admin\AppData\Local\Temp\ipykernel_13800\4266913939.py:6: UserWarning: Th
e figure layout has changed to tight
plt.tight_layout()
C:\Users\Admin\AppData\Local\Temp\ipykernel_13800\4266913939.py:6: UserWarning: Th
e figure layout has changed to tight
plt.tight_layout()
C:\Users\Admin\AppData\Local\Temp\ipykernel_13800\4266913939.py:6: UserWarning: Th
e figure layout has changed to tight
plt.tight_layout()
C:\Users\Admin\AppData\Local\Temp\ipykernel_13800\4266913939.py:6: UserWarning: Th
e figure layout has changed to tight
plt.tight_layout()
C:\Users\Admin\AppData\Local\Temp\ipykernel_13800\4266913939.py:6: UserWarning: Th
e figure layout has changed to tight
plt.tight_layout()
In [ ]: