-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
32 lines (22 loc) · 1.31 KB
/
example.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
#!/usr/bin/python3
import mroc
import math
def test(labels, actual, pred, expected):
r = mroc.mean_roc_auc(labels, actual, pred)
assert math.isnan(r) and math.isnan(expected) or r == expected, 'Expected %f TO EQUAL %f' % (r, expected)
test([0, 0, 0, 0], [0, 1, 1, 0], [0.1, 0.2, 0.3, 0.4], 0.5)
test([0, 0, 0], [0, 1, 1], [0.0, 0.1, 0.1], 1.0)
test([0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0.1, 0.1, 0.0, -0.4, 0.7], 0.25)
test([0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 1, 1], [0.1, 0.5, 0.1, 0.2, 0.2, -7], 0.75)
test([0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0], [2.2, 2.2, 0.1, 0.5, 0.5, 0.5], 0.6666666666666666)
test([0, 0], [0, 0], [1, 1], float('nan'))
test([0, 0, 0, 0, 1, 1, 1], [0, 1, 1, 0, 0, 1, 1], [0.1, 0.2, 0.3, 0.4, 0.0, 0.1, 0.1], 0.75) # combile first 2 tests
test([0, 0, 0, 0, 1, 1, 1], [0, 1, 1, 0, 1, 1, 1], [0.1, 0.2, 0.3, 0.4, 0.0, 0.1, 0.1], 0.5) # combile first test and nan
test([13, 13, 13, 13, 13, 13, 13],
[0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0.],
float('nan'))
test([7, 7, 13, 19, 7, 16, 1, 13, 13, 13, 13, 13, 1, 13, 1],
[1., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[1., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
1)