forked from ravikiranj/twitter-sentiment-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bass_analyze.py
executable file
·73 lines (67 loc) · 2.62 KB
/
bass_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import json,sys
sys.path.append("/home/ravikirn/lib64/python/")
sys.path.append("/home/ravikirn/lib/python/")
sys.path.append("/home/ravikirn/coursework/data-mining/packages/libsvm-3.12/python/")
import get_twitter_data
import baseline_classifier, naive_bayes_classifier, max_entropy_classifier, libsvm_classifier,pickle
keyword = 'iphone'
time = 'today'
#twitterData = get_twitter_data.TwitterData()
#tweets = twitterData.getTwitterData(keyword, time)
infile = open('data/tweets_current.pickle')
tweets = pickle.load(infile)
infile.close()
#algorithm = 'baseline'
#algorithm = 'naivebayes'
#algorithm = 'maxent'
#algorithm = 'svm'
if(len(sys.argv) < 2):
print "Please choose the algorithm to test, syntax = 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
print 'Started to instantiate Naive Bayes Classifier'
sys.stdout.flush()
nb = naive_bayes_classifier.NaiveBayesClassifier(tweets, keyword, time,\
trainingDataFile, classifierDumpFile, trainingRequired)
#nb.classify()
print 'Computing Accuracy'
sys.stdout.flush()
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
print 'Started to instantiate Max Entropy Classifier'
sys.stdout.flush()
maxent = max_entropy_classifier.MaxEntClassifier(tweets, keyword, time,\
trainingDataFile, classifierDumpFile, trainingRequired)
#maxent.analyzeTweets()
#maxent.classify()
print 'Computing Accuracy'
sys.stdout.flush()
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
print 'Started to instantiate SVM Classifier'
sys.stdout.flush()
sc = libsvm_classifier.SVMClassifier(tweets, keyword, time,\
trainingDataFile, classifierDumpFile, trainingRequired)
#sc.classify()
print 'Computing Accuracy'
sys.stdout.flush()
sc.accuracy()
print 'Done'
sys.stdout.flush()