-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphase_3.py
35 lines (32 loc) · 925 Bytes
/
phase_3.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
import json
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn import svm
from sklearn.metrics import classification_report
flnm = "1.txt"
try:
with open(flnm,'r') as readfile:
text_data = readfile.read()
except:
text_data = readfile.read()
print "file error"
finally:
readfile.close()
json_data=json.loads(text_data)
t_d=[]
t_l=[]
for i in json_data:
t_d.append(i['Processed: '])
t_l.append(i['Sentiment: '])
vectorizer = TfidfVectorizer()
train_vectors = vectorizer.fit_transform(t_d)
# Perform classification with SVM, kernel=rbf
classifier_rbf = svm.SVC()
#t0 = time.time()
classifier_rbf.fit(train_vectors, t_l)
#t1 = time.time()
#prediction_rbf = classifier_rbf.predict(test_vectors)
#t2 = time.time()
#time_rbf_train = t1-t0
#time_rbf_predict = t2-t1
a=["democrats inquirey into sessions "]
print classifier_rbf.predict(vectorizer.fit_transform(a))