|
| 1 | +# Test confusion matrix |
| 2 | + |
| 3 | +using Test |
| 4 | +using Clustering |
| 5 | + |
| 6 | +@testset "confusion() (Confusion matrix)" begin |
| 7 | + |
| 8 | + @testset "small size tests" begin |
| 9 | + @test confusion([0,0,0], [0,0,0]) == [3 0; 0 0] |
| 10 | + @test confusion([0,0,1], [0,0,0]) == [1 0; 2 0] |
| 11 | + @test confusion([0,1,1], [0,0,0]) == [1 0; 2 0] |
| 12 | + @test confusion([1,1,1], [0,0,0]) == [3 0; 0 0] |
| 13 | + |
| 14 | + @test confusion([0,0,0], [0,0,1]) == [1 2; 0 0] |
| 15 | + @test confusion([0,0,1], [0,0,1]) == [1 0; 0 2] |
| 16 | + @test confusion([0,1,1], [0,0,1]) == [0 1; 1 1] |
| 17 | + @test confusion([1,1,1], [0,0,1]) == [1 2; 0 0] |
| 18 | + |
| 19 | + @test confusion([0,0,0], [0,1,1]) == [1 2; 0 0] |
| 20 | + @test confusion([0,0,1], [0,1,1]) == [0 1; 1 1] |
| 21 | + @test confusion([0,1,1], [0,1,1]) == [1 0; 0 2] |
| 22 | + @test confusion([1,1,1], [0,1,1]) == [1 2; 0 0] |
| 23 | + |
| 24 | + @test confusion([0,0,0], [1,1,1]) == [3 0; 0 0] |
| 25 | + @test confusion([0,0,1], [1,1,1]) == [1 0; 2 0] |
| 26 | + @test confusion([0,1,1], [1,1,1]) == [1 0; 2 0] |
| 27 | + @test confusion([1,1,1], [1,1,1]) == [3 0; 0 0] |
| 28 | + end |
| 29 | + |
| 30 | + @testset "comparing 2 k-means clusterings" begin |
| 31 | + m = 3 |
| 32 | + n = 100 |
| 33 | + k = 1 |
| 34 | + x = rand(m, n) |
| 35 | + |
| 36 | + # non-weighted |
| 37 | + r1 = kmeans(x, k; maxiter=5) |
| 38 | + r2 = kmeans(x, k; maxiter=5) |
| 39 | + C = confusion(r1, r2) |
| 40 | + @test C == [n*(n-1)/2 0; 0 0] |
| 41 | + end |
| 42 | + |
| 43 | +end |
| 44 | + |
0 commit comments