3
# Benchmark of Quotient spambayes filter, both training and classification.
5
import sys, tempfile, random, time
7
from xquotient.spam import _SQLite3Classifier
9
words = list(open('/usr/share/dict/words', 'r'))
15
return duration / (TRAINING_FACTOR * MESSAGE_FACTOR) * 1000.0
19
prng = random.Random()
23
classifier = _SQLite3Classifier(tempfile.mktemp())
26
for i in range(TRAINING_FACTOR):
27
classifier.learn(words[i:i + MESSAGE_FACTOR], True)
29
for i in range(TRAINING_FACTOR, TRAINING_FACTOR * 2):
30
classifier.learn(words[i:i + MESSAGE_FACTOR], False)
33
print 'Learning: %.2f ms/word' % (adj(after - before),)
36
for i in range(TRAINING_FACTOR * 2):
37
classifier.spamprob(words[i:i + MESSAGE_FACTOR])
40
print 'Guessing: %.2f ms/word' % (adj(after - before),)
43
if __name__ == '__main__':