-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_classifiers.py
48 lines (39 loc) · 1.15 KB
/
test_classifiers.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
43
44
45
46
47
48
#!/usr/bin/env python
#coding=utf-8
import unittest
from numpy import *
from adaboost import AdaBoost
from decision_stump import DecisionStump
import pyroc
def load_bupa_dataset():
"""
The BUPA dataset can be obtained from
http://www.cs.huji.ac.il/~shais/datasets/ClassificationDatasets.html
See description of this dataset at
http://www.cs.huji.ac.il/~shais/datasets/bupa/bupa.names
"""
data = loadtxt('bupa.data',delimiter = ',')
X = data[:,:-1] # features
X = X
Y = data[:,-1]
Y[Y==2] = -1 # labels <- {1, -1}
return X, Y
class AdaBoostTestCase(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testBupaData(self):
X, Y = load_bupa_dataset()
classifier = AdaBoost(DecisionStump)
for t in [100,200,300,400,500]:
score = classifier.test_on_training_set(X,Y,t)
roc = pyroc.ROCData(zip(Y,score))
auc = roc.auc()
print auc
self.failUnless(auc > .9)
def main():
suite = unittest.TestLoader().loadTestsFromTestCase(AdaBoostTestCase)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
main()