-
Notifications
You must be signed in to change notification settings - Fork 0
/
classifier2_CHI.py
49 lines (35 loc) · 1.06 KB
/
classifier2_CHI.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
#!/usr/bin/env python2
"""
Classifier based on Special getTermDocMatrix
* Added the tag NOT to every word between a negation word
(eg: "not") and the first punctuation mark following
the negation word.
"""
from corpusReader import SpecialPolarityDataReader
from classifier import splitData,getClassifier,printTable,classify
dataReader = None;
def loadData():
global dataReader
dataReader = SpecialPolarityDataReader()
dataReader.getDocuments();
dataReader.setTerms(2000,featureSelection='CHI_SQUARE')
def getData():
featuresets = dataReader.getTermDocMatrix()
return featuresets
def main():
loadData();
data = getData();
NBresults = list()
SVMresults = list()
for x in xrange(0,10):
(train_set,test_set) = splitData(data)
classifier = getClassifier(train_set,'NaiveBayes')
NBresults.append(classify(classifier,test_set))
classifier = getClassifier(train_set,'SVM')
SVMresults.append(classify(classifier,test_set))
print '\nNaive Bayes Classifier'
printTable(NBresults)
print '\nSVM'
printTable(SVMresults)
if __name__ == '__main__':
main()