Apply Logistic Regression Model Techniques To Predict Data On Any Dataset
Apply Logistic Regression Model Techniques To Predict Data On Any Dataset
ipynb
In [21]: df = pd.read_csv("blood_pressure.csv")
In [22]: df.head()
0 1 1 11.28 0.90
1 2 0 9.75 0.23
2 3 1 10.79 0.91
3 4 0 11.00 0.43
4 5 1 14.17 0.83
In [23]: df.tail()
In [24]: df.shape
1 of 5 30-10-2024, 22:07
5 - Jupyter Notebook http://localhost:8888/notebooks/Practicals_AI/5.ipynb
In [25]: df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2000 entries, 0 to 1999
Data columns (total 15 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Patient_Number 2000 non-null int64
1 Blood_Pressure_Abnormality 2000 non-null int64
2 Level_of_Hemoglobin 2000 non-null float64
3 Genetic_Pedigree_Coefficient 1908 non-null float64
4 Age 2000 non-null int64
5 BMI 2000 non-null int64
6 Sex 2000 non-null int64
7 Pregnancy 442 non-null float64
8 Smoking 2000 non-null int64
9 Physical_activity 2000 non-null int64
10 salt_content_in_the_diet 2000 non-null int64
11 alcohol_consumption_per_day 1758 non-null float64
12 Level_of_Stress 2000 non-null int64
13 Chronic_kidney_disease 2000 non-null int64
14 Adrenal_and_thyroid_disorders 2000 non-null int64
dtypes: float64(4), int64(11)
memory usage: 234.5 KB
In [26]: df.isnull().sum()
Out[26]: Patient_Number 0
Blood_Pressure_Abnormality 0
Level_of_Hemoglobin 0
Genetic_Pedigree_Coefficient 92
Age 0
BMI 0
Sex 0
Pregnancy 1558
Smoking 0
Physical_activity 0
salt_content_in_the_diet 0
alcohol_consumption_per_day 242
Level_of_Stress 0
Chronic_kidney_disease 0
Adrenal_and_thyroid_disorders 0
dtype: int64
2 of 5 30-10-2024, 22:07
5 - Jupyter Notebook http://localhost:8888/notebooks/Practicals_AI/5.ipynb
In [30]: df = df.drop(['Pregnancy'],axis=1)
In [31]: df = df.drop(['Patient_Number'],axis=1)
In [32]: df.isnull().sum()
Out[32]: Blood_Pressure_Abnormality 0
Level_of_Hemoglobin 0
Genetic_Pedigree_Coefficient 0
Age 0
BMI 0
Sex 0
Smoking 0
Physical_activity 0
salt_content_in_the_diet 0
alcohol_consumption_per_day 0
Level_of_Stress 0
Chronic_kidney_disease 0
Adrenal_and_thyroid_disorders 0
dtype: int64
In [33]: X = df.drop(['Blood_Pressure_Abnormality'],axis=1)
y = df['Blood_Pressure_Abnormality']
3 of 5 30-10-2024, 22:07
5 - Jupyter Notebook http://localhost:8888/notebooks/Practicals_AI/5.ipynb
In [36]: lg.fit(X_train,y_train)
In [39]: confusion_matrix(y_test,y_pred)
In [40]: print(classification_report(y_test,y_pred))
In [43]: FPR
Out[43]: 160.0
In [44]: accuracy_score(y_test,y_pred)
Out[44]: 0.7175
In [45]: precision_score(y_test,y_pred)
Out[45]: 0.6666666666666666
4 of 5 30-10-2024, 22:07
5 - Jupyter Notebook http://localhost:8888/notebooks/Practicals_AI/5.ipynb
In [46]: recall_score(y_test,y_pred)
Out[46]: 0.7231638418079096
In [49]: roc_auc_score(y_test,y_pred)*100
Out[49]: 71.80841630564213
In [ ]:
5 of 5 30-10-2024, 22:07