-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassification.py
65 lines (44 loc) · 1.5 KB
/
classification.py
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
def classifier(leftAngle,rightAngle):
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
from sklearn import metrics
df=pd.read_csv("dataset.csv")
# df.head()
# feature variables
x = df.drop(['Outcome'], axis=1)
# target variable
y = df.Outcome
# y
df1 = df[df['Outcome'] == 1]
y1 = df1.Outcome
# y1
df2 = df[df['Outcome'] == 0]
y2 = df2.Outcome
# y2
df3 = df1.sample(n = 286)
# df3
df_final = pd.concat([df2, df3], axis=0)
# df_final
df_final = df_final.sample(frac = 1)
# df_final
x_final = df_final.drop(['Outcome'], axis=1)
# x_final
y_final = df_final.Outcome
# y_final
x_train, x_test, y_train, y_test = train_test_split(x_final, y_final, test_size=0.2, random_state=1)
x_train, x_val, y_train, y_val = train_test_split(x_train, y_train, test_size=0.25, random_state=1)
model = LogisticRegression()
model = model.fit(x_train,y_train)
y_pred = model.predict(x_test)
# print("Accuracy:",metrics.accuracy_score(y_test, y_pred)*100)
confusion_matrix(y_test,y_pred)
#Evaluation using Classification report
from sklearn.metrics import classification_report
# print(classification_report(y_test,y_pred))
# checking prediction value
out = model.predict([[leftAngle,rightAngle]])
# print(out[0])
return out[0]
# classifier()