1
1
"""
2
- confusion(a::ClusteringResult, b::ClusteringResult) -> Matrix{Int}
3
- confusion(a::ClusteringResult, b::AbstractVector{<:Integer}) -> Matrix{Int}
4
- confusion(a::AbstractVector{<:Integer}, b::ClusteringResult) -> Matrix{Int}
5
- confusion(a::AbstractVector{<:Integer}, b::AbstractVector{<:Integer}) -> Matrix{Int}
2
+ confusion(a::Union{ClusteringResult, AbstractVector},
3
+ b::Union{ClusteringResult, AbstractVector}) -> Matrix{Int}
6
4
7
- Return 2x2 confusion matrix `C` that represents partition co-occurrence or
5
+ Return 2×2 confusion matrix `C` that represents partition co-occurrence or
8
6
similarity matrix between two clusterings by considering all pairs of samples
9
7
and counting pairs that are assigned into the same or into different clusters
10
8
under the true and predicted clusterings.
11
9
12
10
Considering a pair of samples that is in the same group as a **positive pair**,
13
11
and a pair is in the different group as a **negative pair**, then the count of
14
- true positives is `C₀₀ `, false negatives is `C₀₁ `, false positives `C₁₀ `, and
15
- true negatives is `C₁₁ `:
12
+ true positives is `C₁₁ `, false negatives is `C₁₂ `, false positives `C₂₁ `, and
13
+ true negatives is `C₂₂ `:
16
14
17
15
| | Positive | Negative |
18
16
|:--:|:-:|:-:|
19
- |Positive|C₀₀ |C₁₀ |
20
- |Negative|C₀ ₁|C₁₁ |
17
+ |Positive|C₁₁ |C₁₂ |
18
+ |Negative|C₂ ₁|C₂₂ |
21
19
"""
22
20
function confusion (a:: AbstractVector{<:Integer} , b:: AbstractVector{<:Integer} )
23
21
c = counts (a, b)
@@ -27,10 +25,11 @@ function confusion(a::AbstractVector{<:Integer}, b::AbstractVector{<:Integer})
27
25
njs = sum (abs2, sum (c, dims= 1 )) # sum of squares of sums of columns
28
26
29
27
t2 = sum (abs2, c) # sum over rows & columns of nij^2
30
- t3 = nis+ njs
31
- C = Int [(t2- n) / 2 (nis- t2)/ 2 ; (njs- t2)/ 2 (t2+ n^ 2 - t3)/ 2 ]
28
+ t3 = nis + njs
29
+ C = [(t2 - n) ÷ 2 (nis - t2)÷ 2 ; (njs - t2)÷ 2 (t2 + n^ 2 - t3)÷ 2 ]
32
30
return C
33
31
end
32
+
34
33
confusion (a:: ClusteringResult , b:: ClusteringResult ) =
35
34
confusion (assignments (a), assignments (b))
36
35
confusion (a:: AbstractVector{<:Integer} , b:: ClusteringResult ) =
0 commit comments