-
Notifications
You must be signed in to change notification settings - Fork 0
/
testNV.py
42 lines (33 loc) · 1.09 KB
/
testNV.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
from NaiveBayes import NaiveBayes
from ParseText import ParseText
import numpy as np
import timeit
def calldef():
X = np.random.randint(5, size=(6, 100))
y = np.array([1, 2, 3, 4, 5, 6])
from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB()
clf.fit(X, y)
clf.predict(X)
def callcustom():
X = np.random.randint(5, size=(6, 100))
y = np.array([1, 2, 3, 4, 5, 6])
clf = NaiveBayes()
clf.fit(X, y)
clf.predict(X)
def parsecall():
parser = ParseText()
parser.fit(r'./train', delimiter=' ')
if __name__ == '__main__':
# print(timeit.timeit(calldef, number=500))
# print(timeit.timeit(callcustom, number=5000))
# print(timeit.timeit(parsecall, number=1))
parser = ParseText()
X, y = parser.fit(r'./train', delimiter=' ')
clf = NaiveBayes()
clf.fit(X, y)
X, ya = parser.vectorize(r'./test', delimiter=' ')
yp = clf.predict(X)
# print(ya, yp)
from sklearn.metrics import confusion_matrix, accuracy_score
print(confusion_matrix(ya, yp), accuracy_score(ya, yp))