-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloading models.py
224 lines (200 loc) · 6.46 KB
/
loading models.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
from pandas import DataFrame, read_csv
import pandas as pd
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
import numpy as np
import serial
import pyttsx3
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score
from sklearn import svm
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import r2_score
from sklearn import tree
from sklearn.externals import joblib
#df = pd.read_csv('dataset.csv')
#X=df[['THUMB','INDEX','MIDDLE','RING','LITTLE','G1','G2','G3']]
#Y=df[['LABEL']]
ser = serial.Serial('COM5', baudrate = 9600, timeout =1)
for i in range (3):
arduinodata=ser.readline().strip()
values = arduinodata.decode('ascii').split(',')
a, b, c, d, e, f, g, h = [int(s) for s in values]
example = np.array([a, b, c, d, e, f, g, h])
example = example.reshape(1, -1)
# K Nearest Neighbor
#x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, random_state = 60)
#model = KNeighborsClassifier()
#model.fit(x_train,y_train)
#joblib.dump(rf,'randomforest')
mj7 = joblib.load('KNN')
print(mj7.predict(example))
#predicted=model.predict(x_test)
#accuracy = accuracy_score(y_test,predicted)
#print("Accuracy for KNN is ",accuracy)
# Random Forest
#x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, random_state = 60)
#rf = RandomForestRegressor(n_estimators = 1000)
#rf.fit(x_train,y_train)
#predictions = rf.predict(x_test)
#accuracy = r2_score(y_test,predictions)
#print('\nAccuracy for random forest:\n', round(accuracy, 2)*100, '%.')
#joblib.dump(rf,'randomforest')
mj = joblib.load('randomforest')
print(mj.predict(example))
#accuracy1 = r2_score(x_train,y_train)
#print('\nAccuracy for training random forest:\n', round(accuracy1, 2)*100, '%.')
# Naive Bayes
#
#x_train2, x_test2, y_train2, y_test2 = train_test_split(X, Y, test_size=0.3, random_state = 60)
#GNB = GaussianNB()
#GNB.fit(x_train,y_train)
#joblib.dump(GNB,'NaiveBayes')
mj1 = joblib.load('NaiveBayes')
print(mj1.predict(example))
#predicted2 = GNB.predict(x_test2)
#accuracy2 = accuracy_score(y_test2,predicted2)
#print("Accuracy for KNN is ",accuracy2)
# SVM
#x_train3, x_test3, y_train3, y_test3 = train_test_split(X, Y, test_size=0.3, random_state = 60)
#svc = svm.SVC(kernel='linear').fit(x_train,y_train)
#joblib.dump(svc,'SVM')
mj2 = joblib.load('SVM')
print(mj2.predict(example))
#predicted3 = svc.predict(x_test)
#accuracy3 = accuracy_score(y_test,predicted3)
#print("Accuracy for SVM is ",accuracy3)
# Logistic Regression
#x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, random_state = 60)
#clf = LogisticRegression().fit(x_train,y_train)
#joblib.dump(clf,'logistic')
mj3 = joblib.load('logistic')
print(mj3.predict(example))
#predicted4 = clf.predict(x_test)
#accuracy4 = r2_score(y_test,predicted4)
#print("Accuracy for Logistic Regression is ",accuracy4)
# Decision Tree
#Dtree = tree.DecisionTreeClassifier().fit(x_train,y_train)
#joblib.dump(Dtree,'DecisionTree')
mj4 = joblib.load('DecisionTree')
print(mj4.predict(example))
#print(a)
#predicted5 = Dtree.predict(x_test)
#accuracy5 = accuracy_score(y_test,predicted5)
#print("Accuracy for Logistic Regression is ",accuracy5)
#if a <= 1:
#if a > 0 and a <=1 :
# abc = "victory"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 1 and a <=2 :
# abc = "Comehere"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 2 and a <=3 :
# abc = "Okay"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 3 and a <=4 :
# abc = "Stop"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 4 and a <=5 :
# abc = "You"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 5 and a <=6 :
# abc = "Hope"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 6 and a <=7 :
# abc = "Failure"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 7 and a <=8 :
# abc = "Really"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 8 and a <=9 :
# abc = "Quote"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 9 and a <=10 :
# abc = "No"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 10 and a <=11 :
# abc = "I Love you"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 11 and a <=12 :
# abc = "Livelong"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 12 and a <=13 :
# abc = "Thats it"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 13 and a <=14 :
# abc = "Solidarity"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 14 and a <=15 :
# abc = "Rock On"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 15 and a <=16 :
# abc = "Good Bye"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 16 and a <=17 :
# abc = "What is wrong"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 17 and a <=18 :
# abc = "Why"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()
#elif a > 18 and a <= 19 :
# abc = "Rest room"
# engine = pyttsx3.init()
# engine.say('Predicted Output')
# engine.say(abc)
# engine.runAndWait()