updates + sqlite db
This commit is contained in:
19
run.py
19
run.py
@@ -14,7 +14,7 @@ from storage.fetch_mail import fetch_threads, flatten_threads
|
||||
from storage import Mail, MailThread, db_session
|
||||
import yaml
|
||||
import email
|
||||
from classifier import get_training_threads, ThreadDictExtractor, pipe1, print_answers, in_training, store_training_data, pipe2
|
||||
from classifier import get_training_threads, ThreadDictExtractor, pipe1, print_answers, in_training, store_training_data, pipe2, pipe2b
|
||||
from sklearn.pipeline import Pipeline
|
||||
from sklearn.preprocessing import LabelEncoder
|
||||
import numpy
|
||||
@@ -32,6 +32,16 @@ def train_fit_pipe2():
|
||||
pipe2.fit(tt[0],tt[1])
|
||||
return pipe2,tt[2]
|
||||
|
||||
def train_fit_pipe2b():
|
||||
tt= get_training_threads(b"maintopic")
|
||||
pipe2b.fit(tt[0],tt[1])
|
||||
return pipe2b,tt[2]
|
||||
|
||||
def predict_thread(p,l,t):
|
||||
pre=p.predict([t])
|
||||
print "Status is answered is estimated to be: " + str(l.inverse_transform(pre)[0])
|
||||
return pre
|
||||
|
||||
|
||||
def train_single_thread(tid,p,le,key="answered"):
|
||||
if (not type(tid) is int): raise TypeError("ID must be of type int")
|
||||
@@ -43,8 +53,8 @@ def train_single_thread(tid,p,le,key="answered"):
|
||||
pre=p.predict([mth])
|
||||
answ=pre[0]
|
||||
#
|
||||
print mth.to_text()
|
||||
print mth.text()
|
||||
# print mth.to_text()
|
||||
# print mth.text()
|
||||
print "Status is answered is estimated to be: " + str(le.inverse_transform(pre)[0])
|
||||
print_answers(le)
|
||||
|
||||
@@ -104,9 +114,11 @@ if len(sys.argv)>1:
|
||||
|
||||
if sys.argv[1] == "train_thrd2":
|
||||
p, le=train_fit_pipe2()
|
||||
pb, lb =train_fit_pipe2b()
|
||||
train_single_thread(int(sys.argv[2]),p,le,b"maintopic")
|
||||
if sys.argv[1] == "train_all2":
|
||||
p, labelencoder=train_fit_pipe2()
|
||||
pb, lb=train_fit_pipe2b()
|
||||
mth=db_session.query(MailThread).all()
|
||||
print mth
|
||||
for t in mth:
|
||||
@@ -115,6 +127,7 @@ if len(sys.argv)>1:
|
||||
print "---------------------------------------------------"
|
||||
print t.firstmail
|
||||
print t.text()
|
||||
predict_thread(pb,lb,t)
|
||||
train_single_thread(t.firstmail, p, labelencoder, b"maintopic")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user