roc 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/roc.rb +1 -0
- data/roc.gemspec +1 -1
- data/samples/a.rb +3 -0
- data/test/roc.rb +24 -34
- metadata +2 -2
data/lib/roc.rb
CHANGED
data/roc.gemspec
CHANGED
data/samples/a.rb
CHANGED
data/test/roc.rb
CHANGED
@@ -4,51 +4,41 @@ $:.unshift('..')
|
|
4
4
|
$:.unshift('../lib')
|
5
5
|
|
6
6
|
require('test/unit')
|
7
|
-
require('
|
7
|
+
require('roc')
|
8
8
|
|
9
9
|
|
10
10
|
class T < Test::Unit::TestCase
|
11
11
|
|
12
|
-
# simple usage
|
13
|
-
#
|
14
|
-
|
12
|
+
# simple usage
|
15
13
|
def test_0010
|
16
|
-
|
17
|
-
|
14
|
+
r = ROCarray.new %w(P N P)
|
15
|
+
assert r.auc == 0.5
|
18
16
|
end
|
19
17
|
|
20
|
-
# it
|
21
|
-
#
|
18
|
+
# without positive samples, it should be nil
|
22
19
|
def test_0020
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
4.times do
|
27
|
-
result = {}
|
28
|
-
|
29
|
-
strategies.each do |strategy|
|
30
|
-
a = Time.now.to_f
|
31
|
-
(0..4).send(strategy){|i| sleep 0.2}
|
32
|
-
b = Time.now.to_f
|
33
|
-
elapsed = b - a
|
34
|
-
result[strategy] = elapsed
|
35
|
-
end
|
36
|
-
|
37
|
-
assert result[:forkoff] < result[:each], 'forkoff is faster than each for long running tasks'
|
38
|
-
end
|
20
|
+
r = ROCarray.new %w(NN)
|
21
|
+
assert r.auc == nil
|
39
22
|
end
|
40
23
|
|
41
|
-
#
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
(0...4).forkoff(2) do |i|
|
46
|
-
sleep i.modulo(2)
|
47
|
-
end
|
48
|
-
b = Time.now.to_f
|
49
|
-
elapsed = b - a
|
50
|
-
assert elapsed < 2
|
24
|
+
# without negative samples, it should be nil
|
25
|
+
def test_0025
|
26
|
+
r = ROCarray.new %w(PP)
|
27
|
+
assert r.auc == nil
|
51
28
|
end
|
52
29
|
|
30
|
+
# only equal predictions -> 0.5
|
31
|
+
def test_0030
|
32
|
+
r = ROCarray.new %w(PPPPPPPPPPNNNNNNNNNN)
|
33
|
+
d = 1e-12
|
34
|
+
assert r.auc>0.5-d and r.auc<0.5+d
|
35
|
+
end
|
36
|
+
|
37
|
+
# initialization with prediction values
|
38
|
+
def test_0040
|
39
|
+
assert ROCarray.new([1.0 , 2.0 , 3.0],[0]).auc==0.0 and
|
40
|
+
ROCarray.new([1.0 , 2.0 , 3.0],[1]).auc==0.5 and
|
41
|
+
ROCarray.new([1.0 , 2.0 , 3.0],[2]).auc==1.0
|
42
|
+
end
|
53
43
|
|
54
44
|
end
|