Skip to content

Commit

Permalink
Add try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Mar 13, 2018
1 parent a24f3ab commit 82dda8b
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions server/ai/src/learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,35 @@ def do_classification(self, header, csv_data):
continue
payload['predictions'].append(predict_payload)

t2 = time.time()
name = "Extended Naive Bayes"
clf = ExtendedNaiveBayes(self.family,path_to_data=self.path_to_data)
predictions = clf.predict_proba(header,csv_data)
predict_payload = {'name': name,'locations': [], 'probabilities': []}
for tup in predictions:
predict_payload['locations'].append(str(self.naming['from'][tup[0]]))
predict_payload['probabilities'].append(round(tup[1],2))
payload['predictions'].append(predict_payload)
self.logger.debug("{} {:d} ms".format(name,int(1000 * (t2 - time.time()))))
try:
t2 = time.time()
name = "Extended Naive Bayes"
clf = ExtendedNaiveBayes(self.family,path_to_data=self.path_to_data)
predictions = clf.predict_proba(header,csv_data)
predict_payload = {'name': name,'locations': [], 'probabilities': []}
for tup in predictions:
predict_payload['locations'].append(str(self.naming['from'][tup[0]]))
predict_payload['probabilities'].append(round(tup[1],2))
payload['predictions'].append(predict_payload)
self.logger.debug("{} {:d} ms".format(name,int(1000 * (t2 - time.time()))))
except Exception as e:
self.logger.error(str(e))

t2 = time.time()
name = "Extended Naive Bayes2"
clf = ExtendedNaiveBayes2(self.family, path_to_data=self.path_to_data)
predictions = clf.predict_proba(header, csv_data)
predict_payload = {'name': name, 'locations': [], 'probabilities': []}
for tup in predictions:
predict_payload['locations'].append(
str(self.naming['from'][tup[0]]))
predict_payload['probabilities'].append(round(tup[1], 2))
payload['predictions'].append(predict_payload)
self.logger.debug("{} {:d} ms".format(
name, int(1000 * (t2 - time.time()))))
try:
t2 = time.time()
name = "Extended Naive Bayes2"
clf = ExtendedNaiveBayes2(self.family, path_to_data=self.path_to_data)
predictions = clf.predict_proba(header, csv_data)
predict_payload = {'name': name, 'locations': [], 'probabilities': []}
for tup in predictions:
predict_payload['locations'].append(
str(self.naming['from'][tup[0]]))
predict_payload['probabilities'].append(round(tup[1], 2))
payload['predictions'].append(predict_payload)
self.logger.debug("{} {:d} ms".format(
name, int(1000 * (t2 - time.time()))))
except Exception as e:
self.logger.error(str(e))

self.logger.debug("{:d} ms".format(int(1000 * (t - time.time()))))
return payload
Expand Down Expand Up @@ -202,16 +208,22 @@ def learn(self, fname):
t2 = time.time()
name = "Extended Naive Bayes"
clf = ExtendedNaiveBayes(self.family, path_to_data=self.path_to_data)
clf.fit(fname)
self.logger.debug("learned {}, {:d} ms".format(
name, int(1000 * (t2 - time.time()))))
try:
clf.fit(fname)
self.logger.debug("learned {}, {:d} ms".format(
name, int(1000 * (t2 - time.time()))))
except Exception as e:
self.logger.error(str(e))

t2 = time.time()
name = "Extended Naive Bayes2"
clf = ExtendedNaiveBayes2(self.family, path_to_data=self.path_to_data)
clf.fit(fname)
self.logger.debug("learned {}, {:d} ms".format(
name, int(1000 * (t2 - time.time()))))
try:
clf.fit(fname)
self.logger.debug("learned {}, {:d} ms".format(
name, int(1000 * (t2 - time.time()))))
except Exception as e:
self.logger.error(str(e))

self.logger.debug("{:d} ms".format(int(1000 * (t - time.time()))))

Expand Down

0 comments on commit 82dda8b

Please sign in to comment.