-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trial.py
29 lines (27 loc) · 923 Bytes
/
Trial.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
from BayesClassifier import *
from DataReader import *
def testClassifier(outputLabel):
bc = BayesClassifier()
bc.train(outputLabel + ".train")
reader = DataReader(outputLabel + ".test")
correctLabel = {}
numberGuess = {}
correct = 0.0
total = 0.0
for label, tokens in reader:
if not label in correctLabel:
correctLabel[label] = 0.0
guess = bc.classify(" ".join(tokens))
if not guess in numberGuess:
numberGuess[guess] = 0.0
if guess == label:
correctLabel[guess] += 1
correct += 1
numberGuess[guess] += 1
total += 1
for label in correctLabel:
print "Correct " + label, "-", correctLabel[label]/numberGuess[label]
print "Total accuracy -", correct / total
dataTopic = "movies"
split("data/movies.data", dataTopic)
testClassifier(dataTopic)