-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (28 loc) · 1.14 KB
/
main.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
from bayes import Article, NaiveBayesTextClassification
from uuid import uuid4
def build_articles():
result = [Article(uuid4(), '123456af', 'C1'),
Article(uuid4(), 'asdkahfjahjkfakfhoagj14', 'C2'),
Article(uuid4(), '234576080705746911111111111111111111ab', 'C1'),
Article(uuid4(), 'sadkpocsakopckpamlfmng sada23', 'C2'),
Article(uuid4(), '34850285426240692806aj', 'C1')]
return result
def try_bernoulli():
model = NaiveBayesTextClassification(method='Bernoulli')
model.fit_mul(build_articles())
model.train()
print(model.predict(Article(uuid4(), '34850285426240692806A', None)))
print(model.predict(Article(uuid4(), 'defrtjhrtjA', None)))
pass
def try_gaussian():
model = NaiveBayesTextClassification(method='Gaussian')
model.fit_mul(build_articles())
model.train()
print(model.predict(Article(uuid4(), '34850285426240692806A', None)))
print(model.predict(Article(uuid4(), 'defrtjhrtjA', None)))
print(model.predict_label(Article(uuid4(), 'defrtjhrtjA', None)))
pass
if __name__ == '__main__':
# try_bernoulli()
try_gaussian()
pass