-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassifier.py
More file actions
32 lines (25 loc) · 783 Bytes
/
classifier.py
File metadata and controls
32 lines (25 loc) · 783 Bytes
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
import libGeneral
import os
import sqlite3
import math
import bayes_classifier
import kNN_classifier
######################
DATABASE_NAME = "ex4.db"
TEST_PATH = "u4_test/"
GLOBAL_INDEX = "globalIndex";
RELPROB_PATH = "bayes_model/";
######################
connection = sqlite3.connect(DATABASE_NAME)
testFiles = os.listdir(TEST_PATH)
globalIndex = libGeneral.readDictionaryFromDisk(GLOBAL_INDEX)
######################
resultDictionary = {}
for testFile in testFiles:
wordVector = libGeneral.createWordVector(TEST_PATH + testFile)
#probs = bayes_classifier.classify(wordVector)
probs = kNN_classifier.classify(wordVector,7)
resultDictionary[testFile] = probs[0]
print probs
print "##########"
libGeneral.writeDictionaryToDisk(resultDictionary, "G02_predictions.txt")