Professional Documents
Culture Documents
Seaborn - Plots - Jupyter Notebook
Seaborn - Plots - Jupyter Notebook
Out[3]:
age gender cp trestbps chol fps restecg thalach exang oldpeak slope ca thal class
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 1/36
6/9/2021 Seaborn_plots - Jupyter Notebook
In [4]: a=data['class'].groupby(data.gender).value_counts()
b=pd.pivot_table(data= data, values=['class'], index= ['gender'], aggfunc= ['count'])
c=b.max()
bbox = dict(boxstyle ="round", fc ="0.8")
arrowprop=dict(facecolor ='green',shrink = 0.05)
data.sort_values(by='age')
...
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 2/36
6/9/2021 Seaborn_plots - Jupyter Notebook
thal: A blood disorder called thalassemia (3 = normal; 6 = fixed defect; 7 = reversable defect)
Class : Patient Symptoms (0-4)
0: no symptoms wer shown
1 No limitation of physical activity. Ordinary physical activity does not cause undue fatigue, palpitation, dyspnea
(shortness of breath).
2 Slight limitation of physical activity. Comfortable at rest. Ordinary physical activity results in fatigue,
palpitation, dyspnea (shortness of breath).
3 Marked limitation of physical activity. Comfortable at rest. Less than ordinary activity causes fatigue,
palpitation, or dyspnea.
4 Unable to carry on any physical activity without discomfort. Symptoms of heart failure at rest. If any physical
activity is undertaken, discomfort increases.
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 3/36
6/9/2021 Seaborn_plots - Jupyter Notebook
In [5]: sns.displot(data=data,x='age',multiple='stack',col='gender')
plt.show()
This plot gives the info about the data in respect to the number of samples taken in respect to Male Female and in respect to age - it hepls us to
understand there are more number of females
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 4/36
6/9/2021 Seaborn_plots - Jupyter Notebook
In [48]: plt.figure(figsize=(10,10))
plt.subplot(221)
b1=sns.countplot(data= data, x='gender',hue='cp')
plt.title('Gender v/s Count in chest pain moderation \n')
#Patients are suffering with various chest pain intensity(1-4) divided by gender
plt.subplot(222)
b2=sns.countplot(data=data,x='gender',hue='class')
plt.title('gender v/s count in classes')
#Patients classification into classes divided by gender
plt.subplot(223)
sns.countplot(data= data, x='cp',hue='class')
plt.title('Chest Pain Type v/s Count in Class of heart ache \n')
#number of patients with various levels of Chest pain intensity divided by class
plt.tight_layout() # adjusts the plot assembly
sns.catplot(x="exang", hue="slope",data=data, col='gender',kind='count')
#It tells about the count of excersice induced anigma divided by slope of ECG plot
plt.show()
print('Jus for verification the numbers : \n ',a)
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 5/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 6/36
6/9/2021 Seaborn_plots - Jupyter Notebook
Graph 1: It was observed that more number of samples with the high intensity chest pain is observed in Male - while
the higher count with least intensity is observed in male
Graph 2: High number of male and Female falls under class 0 level of heart ache and the least falls under clas 4 in
both male and female - Male count in individual cases are more
Graph 3: It was understood that people in class 0 has higher rate of Chest pain level-3 in effect of heart attack event
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 7/36
6/9/2021 Seaborn_plots - Jupyter Notebook
Graph4:It was understood that the Male samples are high in numvber with positive slope on ECG who are not exhibiting
Excersice induced angima
While there are large number of male who has Excersice angima has flat ECG report comparetively
Negative slope in ECG id exhibited by non Excersice Engima patients in male samples
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 8/36
6/9/2021 Seaborn_plots - Jupyter Notebook
In [139]: plt.figure(figsize=(16,7))
d1=sns.distplot(data[data['slope']==1]['age'],kde=True,rug=True,color='red')
d2=sns.displot(data[data['slope']==2]['age'],kde=True,color='blue')
d3=sns.displot(data[data['slope']==3]['age'],kde=True,color='green')
plt.title('Age of Patients with Flat ECG\n')
plt.show()
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 9/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 10/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 11/36
6/9/2021 Seaborn_plots - Jupyter Notebook
In [144]: e1=sns.distplot(data[data['class']==4]['age'],rug=True,color='violet',hist=False)
e2=sns.distplot(data[data['class']==3]['age'],kde=True,color='indigo',hist=False)
e3=sns.distplot(data[data['class']==2]['age'],kde=True,color='blue',hist=False)
e4=sns.distplot(data[data['class']==1]['age'],kde=True,color='green',hist=False)
e5=sns.distplot(data[data['class']==0]['age'],kde=True,color='yellow',hist=False)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 12/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 13/36
6/9/2021 Seaborn_plots - Jupyter Notebook
In [92]: f1=sns.distplot(data[data['class']==4]['chol'],rug=True,color='violet',hist=False)
f2=sns.distplot(data[data['class']==3]['chol'],rug=True,color='red',hist=False)
f3=sns.distplot(data[data['class']==2]['chol'],rug=True,color='yellow',hist=False)
f4=sns.distplot(data[data['class']==1]['chol'],rug=True,color='green',hist=False)
f5=sns.distplot(data[data['class']==0]['chol'],rug=True,color='maroon',hist=False)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
warnings.warn(msg, FutureWarning)
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 14/36
6/9/2021 Seaborn_plots - Jupyter Notebook
The above maps has the various plots related to the Cholestrol level in various class
Class:4- Violet - Choletrso levels states at 200-250
Class3- Red Cholestrol level states at 300-325
Class2- Yellow - Cholestrol level is at 250-280 range
Class1- Green - Cholestrol level is at 280-295
Class 0 - Maroon - Cholestrol level is at 200
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 15/36
6/9/2021 Seaborn_plots - Jupyter Notebook
warnings.warn(
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 16/36
6/9/2021 Seaborn_plots - Jupyter Notebook
It gives the details about age vs the blood pressure - it was found that the between the age of 50-60 years the itensity of the blood pressure
In [ ]:
this tells that the intensity of cholestraol level in various ages - the mis line indicates the average of the values in the level
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 17/36
6/9/2021 Seaborn_plots - Jupyter Notebook
This tells that the many patients at 65Years+ (even when the avg is taken out) have elivated blood pressure levels
(not considering the gender of the patient)
# Joint plots
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 18/36
6/9/2021 Seaborn_plots - Jupyter Notebook
In [97]: jp1 = data[data['class'] == 4 ][['age', 'gender', 'cp', 'trestbps', 'chol', 'fps', 'restecg', 'thalach','exang', 'oldpeak
#class 4 patients - people with heart disease
pal = sns.light_palette("blue", as_cmap=True)
print('Age vs trestbps(Heart Diseased Patinets)')
sns.jointplot(data=df3, x='age',y='trestbps', kind='kde',cmap='Reds')
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 19/36
6/9/2021 Seaborn_plots - Jupyter Notebook
For the Class 4 category patient samples - It was found that the from the age group 50-60 it was found that the
cholestrol levels are upto 140-160 mm/Hg and the number of patents are more at age group of 60-70
Form the above graph it was observed that the Cholestrol levels at 200-250mg/dl has higher blood pressure 130 mm/Hg
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 20/36
6/9/2021 Seaborn_plots - Jupyter Notebook
From the above graph It was Observed that the MAx hear reate achvived by max number of patients is at 150-175bpm and
also has Cholestrol level of 250 mg/dl
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 21/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 22/36
6/9/2021 Seaborn_plots - Jupyter Notebook
# Correlation Maps
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 23/36
6/9/2021 Seaborn_plots - Jupyter Notebook
In [48]: plt.figure(figsize=(12,10))
sns.heatmap(data.corr(),annot=True,cmap="Pastel1",fmt='.2f',linewidth=1.2,cbar=False)
Out[48]: <AxesSubplot:>
The corelation maps gives information about almost everything with every factor:
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 24/36
6/9/2021 Seaborn_plots - Jupyter Notebook
Age :
1.Age is an aspect most effected on the no of major vessels in trouble and also trestbps value (blood pressure )
2.When Age is incresing the max hear rate achevied is decresing
Gender :
1.Gender has least effect on all the values while the blood disorder has significant effect -
2. It also has significant effect on the patient symptoms
Chest pain:
1.Chest pain has major relation withthe symptoms of the patient
2.It also have the considerate effect by Exercise induced angina
3.At the stage of the max Chest pain the max heart rate achived very less
Blood pressure:
1.When the blood pressure is varied it has effect on the ST position of ECG
2.bood pressure has the effect on the fast blood pressure
Cholestral:
1.Cholestral will have the Effect on the rest ECG value
Fast blood Pressure :
1.fast blood pressure has an significance effect on the number of artery in trouble
Rest ECG :
1.reading the Rest ECG scan will predict the in which class the patient will be clasified.
Excersice induced angina:
1.blood disorder has an effect on the Excersice Induced angina
old peak:
1.ST positio on ECG is decided with the slope of the ST and it also decide which class the patient can be
classified
Slope :
1. the slope of ECG is also enough for the class decision without looking into ST position of ECG
no. of major vessels :
1.the number of major vessel damage has effect on the which classifies class the patient to put into
Blood disorder:
1. blood disorder also has effect on the patient heart attack and which class the patient to put into
# Cluster maps
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 25/36
6/9/2021 Seaborn_plots - Jupyter Notebook
In [113]: cm=sns.clustermap(data.corr(),annot=True)
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 26/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 27/36
6/9/2021 Seaborn_plots - Jupyter Notebook
#You can also hide the colorbar entirely using the cbar=False option
#You can add lines between the squares in the heatmap using the linewidths argument
#You can also add annotations to the heatmap using the annot=True argument
#You can also change the color theme using the cmap argument. For example, you could set the colors to range from
yellow to green to blue -
----- creating a colormap
colormap = sns.color_palette("ocean_r")
In [116]: sns.pairplot(data,col='ca',hue='class')
---------------------------------------------------------------------------
<ipython-input-116-c22b7e6baf9c> in <module>
----> 1 sns.pairplot(data,col='ca',hue='class')
44 )
47 return inner_f
48
# Categorical plots
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 28/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 29/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 30/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 31/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 32/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 33/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 34/36
6/9/2021 Seaborn_plots - Jupyter Notebook
the abve graphs indicates the various plots comparing the Excersice induces anigma va the Cholestrol its affects on the
slop of ECG which is divided by gender
It was understood that the large part of female who ha sno excersice induced angima has postive slope of the ECG
while the male has positive slope has the cholestrol levls around 300 are high in number
the negative slope of ECG results in Male ha svag levvels of cholestrol less than 250
box & violain & bar plots has better visuavalization
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 35/36
6/9/2021 Seaborn_plots - Jupyter Notebook
localhost:8888/notebooks/Downloads/Seaborn_plots.ipynb# 36/36