-
Notifications
You must be signed in to change notification settings - Fork 0
/
spam_with_NB.py
38 lines (33 loc) · 1.06 KB
/
spam_with_NB.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
from sklearn.naive_bayes import GaussianNB
from sklearn.naive_bayes import ComplementNB
from sklearn.naive_bayes import MultinomialNB
from sklearn.naive_bayes import BernoulliNB
def gaussian_NB(train_data, train_label, test_data):
''' acc: 0.21 err:0.79 AUC:0.47
return: pre_val
'''
gnb = GaussianNB()
gnb.fit(train_data, train_label)
pre_val = gnb.predict(test_data)
return pre_val
def complement_NB(train_data, train_label, test_data):
gnb = ComplementNB()
gnb.fit(train_data, train_label)
pre_val = gnb.predict(test_data)
return pre_val
def bernoulli_NB(train_data, train_label, test_data):
''' acc: 0.79 err:0.21 AUC:0.82
return: pre_val
'''
gnb = BernoulliNB()
gnb.fit(train_data, train_label)
pre_val = gnb.predict(test_data)
return pre_val
def multinomial_NB(train_data, train_label, test_data):
''' acc: 0.73 err:0.26 AUC:0.66
return: pre_val
'''
gnb = MultinomialNB()
gnb.fit(train_data, train_label)
pre_val = gnb.predict(test_data)
return pre_val