Assignment 1
Assignment 1
PM 1
In [3]: dataFrame=pd.read_csv('heart.csv')
In [5]: dataFrame.shape
In dataFrame.head()
[7]:
Unnamed: Age Sex ChestPain RestBP Chol Fbs RestECG MaxHR
Out[7]: 0 ExAng O
In [9]: dataFrame.tail()
Out[9]: Unnamed
Age Sex ChestPain RestB Chol Fbs RestEC MaxHR ExAng
:
P G
0
298 299 45 1 typical 110 264 0 0 132 0
In [13]: dataFrame.dtypes
file:///C:/Users/Student/Downloads/Assignment1 1/11
(5).html
10/17/24, 4:05 Assignment
PM 1
In [15]: dataFrame.describe()
In [17]: dataFrame.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 303 entries, 0 to 302
Data columns (total 14 columns):
# Column Non-Null Count Dtype
file:///C:/Users/Student/Downloads/Assignment1 2/11
(5).html
10/17/24, 4:05 Assignment
PM 1
7 MaxHR 30 non-null int64
3
8 ExAng 30 non-null int64
3
9 Oldpeak 30 non-null float64
3
1 Slope 30 non-null int64
0 3
1 Ca 29 non-null float64
1 9
1 Thal 30 non-null object
2 1
1 AHD 30 non-null object
3 3
dtypes: float64(2), int64(9), object(3)
memory usage: 33.3+ KB
file:///C:/Users/Student/Downloads/Assignment1 3/11
(5).html
10/17/24, 4:05 Assignment
PM 1
In [19]: dataFrame.Ca.value_counts()
Out[19]: Ca
0.0 176
1.0 65
2.0 38
3.0 20
Name: count, dtype:
int64
In [21]: dataFrame.Sex.value_counts()
Out[21] Sex
:
1 206
0 97
Name: count, dtype: int64
dataFrame.isnull()
In
[23]:
Out[23]: Age Sex ChestPai RestB Chol Fbs RestEC MaxHR ExAng Oldpea S
n P G k
0 False False False False False False False False False False
1 False False False False False False False False False False
2 False False False False False False False False False False
3 False False False False False False False False False False
4 False False False False False False False False False False
... ... ... ... ... ... ... ... ... ... ...
298 False False False False False False False False False False
299 False False False False False False False False False False
300 False False False False False False False False False False
301 False False False False False False False False False False
302 False False False False False False False False False False
In [25]: dataFrame.isnull().sum()
file:///C:/Users/Student/Downloads/Assignment1 4/11
(5).html
10/17/24, 4:05 Assignment
PM 1
Out[25]: Age 0
Sex 0
ChestPain 0
RestBP 0
Chol 0
Fbs 0
RestECG 0
MaxHR 0
ExAng 0
Oldpeak 0
Slope 0
Ca 4
Thal 2
AHD 0
dtype:
int64
In [27]: dataFrame.Age.mean()
Out[27]: 54.43894389438944
In [29]: dataFrame.describe()
In [31]: dataFrame["Age"].mean(axis=0)
Out[31]: 54.43894389438944
In [33]: var=dataFrame.loc[:,['Age','Sex','ChestPain','RestBP','Chol']]
In [35]: var
file:///C:/Users/Student/Downloads/Assignment1 5/11
(5).html
10/17/24, 4:05 Assignment
PM 1
In [39]: tp=9
0
fp=1
1
fn=1
9
tn=4
0
acc=(tp+tn)/(tp+fp+fn+tn)
pre=tp/(tp+fp)
rec=tp/(tp+fn)
print("Accuracy is : {}".format(acc))
Accuracy is : 0.8125
Precision is : 0.8910891089108911
Recall is : 0.8256880733944955
F1-Score is : 0.8571428571428572
In [43]: dataFrame.plot();
file:///C:/Users/Student/Downloads/Assignment1 6/11
(5).html
10/17/24, 4:05 Assignment
PM 1
In [47]: sns.pairplot(var);
file:///C:/Users/Student/Downloads/Assignment1 7/11
(5).html
10/17/24, 4:05 Assignment
PM 1
In [49]: labels=['Male','Female']
dataFrame.Sex.value_counts().plot(kind= "pie",labels
=labels,startangle=90,shado
explode=(0,0),autopct='%1.1f%%' );
file:///C:/Users/Student/Downloads/Assignment1 8/11
(5).html
10/17/24, 4:05 Assignment
PM 1
file:///C:/Users/Student/Downloads/Assignment1 9/11
(5).html
10/17/24, 4:05 Assignment
PM 1
plt.show()
file:///C:/Users/Student/Downloads/Assignment1 10/
(5).html 11
10/17/24, 4:05 Assignment
PM 1
In [ ]:
file:///C:/Users/Student/Downloads/Assignment1 11/
(5).html 11