-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogistic_Regression.py
More file actions
69 lines (47 loc) · 1.28 KB
/
Logistic_Regression.py
File metadata and controls
69 lines (47 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
"""Logisitic_regression
Original file is located at
https://colab.research.google.com/drive/1DjdYEXO3H7FOmTAQRedyJQkqDMsG_FiR
## Data_Preprocessing
"""
pip install pandas
import numpy as np
import matplotlib.pyplot as mtp
import pandas as pd
df=pd.read_csv("/content/framingham.csv")
df
missing_val=["heartRate","glucose"]
for i in missing_val:
mean_val=df[i].mean()
df[i].fillna(mean_val,inplace=True)
x=df.iloc[:,[14]].values
y=df.iloc[:,[15]].values
a=df["TenYearCHD"].value_counts()[0]
b=df["TenYearCHD"].value_counts()[1]
print(a,b)
#independent variable
x
#Dependent
y
type(y)
#splitting train and test set
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.25,random_state=0)
x_train
"""## Feature Scaling"""
from sklearn.preprocessing import StandardScaler
st_x= StandardScaler()
x_train= st_x.fit_transform(x_train)
x_test= st_x.transform(x_test)
"""##Model Fitting"""
from sklearn.linear_model import LogisticRegression
classifier= LogisticRegression(random_state=0)
classifier.fit(x_train, y_train)
"""# Prediction"""
y_pred=classifier.predict(x_test)
y_pred
"""## Testing"""
from sklearn.metrics import confusion_matrix
cm= confusion_matrix(y_test,y_pred)
#confusion matrix
cm