forked from ravikiranj/twitter-sentiment-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze.py
executable file
·54 lines (48 loc) · 1.97 KB
/
analyze.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
import get_twitter_data
import baseline_classifier, naive_bayes_classifier, max_entropy_classifier, libsvm_classifier
import json,sys,pickle
keyword = 'iphone'
time = 'today'
twitterData = get_twitter_data.TwitterData()
tweets = twitterData.getTwitterData(keyword, time)
#algorithm = 'baseline'
#algorithm = 'naivebayes'
#algorithm = 'maxent'
#algorithm = 'svm'
if(len(sys.argv) < 2):
print "Please choose the algorithm to test, sytanx = python analyze.py (svm|naivebayes|maxent)"
exit()
algorithm = sys.argv[1]
if(algorithm == 'baseline'):
bc = baseline_classifier.BaselineClassifier(tweets, keyword, time)
bc.classify()
val = bc.getHTML()
elif(algorithm == 'naivebayes'):
trainingDataFile = 'data/training_trimmed.csv'
#trainingDataFile = 'data/full_training_dataset.csv'
classifierDumpFile = 'data/test/naivebayes_test_model.pickle'
trainingRequired = 1
nb = naive_bayes_classifier.NaiveBayesClassifier(tweets, keyword, time,\
trainingDataFile, classifierDumpFile, trainingRequired)
nb.classify()
nb.accuracy()
elif(algorithm == 'maxent'):
#trainingDataFile = 'data/training_trimmed.csv'
trainingDataFile = 'data/full_training_dataset.csv'
classifierDumpFile = 'data/test/maxent_test_model.pickle'
trainingRequired = 1
maxent = max_entropy_classifier.MaxEntClassifier(tweets, keyword, time,\
trainingDataFile, classifierDumpFile, trainingRequired)
#maxent.analyzeTweets()
maxent.classify()
maxent.accuracy()
elif(algorithm == 'svm'):
trainingDataFile = 'data/training_trimmed.csv'
#trainingDataFile = 'data/full_training_dataset.csv'
classifierDumpFile = 'data/test/svm_test_model.pickle'
trainingRequired = 1
sc = libsvm_classifier.SVMClassifier(tweets, keyword, time,\
trainingDataFile, classifierDumpFile, trainingRequired)
sc.classify()
sc.accuracy()
print 'Done'