11"""
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}
64
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
86similarity matrix between two clusterings by considering all pairs of samples
97and counting pairs that are assigned into the same or into different clusters
108under the true and predicted clusterings.
119
1210Considering a pair of samples that is in the same group as a **positive pair**,
1311and 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₂₂ `:
1614
1715| | Positive | Negative |
1816|:--:|:-:|:-:|
19- |Positive|C₀₀ |C₁₀ |
20- |Negative|C₀ ₁|C₁₁ |
17+ |Positive|C₁₁ |C₁₂ |
18+ |Negative|C₂ ₁|C₂₂ |
2119"""
2220function confusion (a:: AbstractVector{<:Integer} , b:: AbstractVector{<:Integer} )
2321 c = counts (a, b)
@@ -27,10 +25,11 @@ function confusion(a::AbstractVector{<:Integer}, b::AbstractVector{<:Integer})
2725 njs = sum (abs2, sum (c, dims= 1 )) # sum of squares of sums of columns
2826
2927 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 ]
3230 return C
3331end
32+
3433confusion (a:: ClusteringResult , b:: ClusteringResult ) =
3534 confusion (assignments (a), assignments (b))
3635confusion (a:: AbstractVector{<:Integer} , b:: ClusteringResult ) =
0 commit comments