After doing clustering, the labels found are meaningless. One can calculate a contingency table to see which labels are most related to the original classes if the ground-truth is available.
I want to automatically permute columns of a contingency table to maximize its diagonal. For example:
# Ground-truth labels
c1 = c(1,1,1,1,1,2,2,2,3,3,3,3,3,3,3)
# Labels found
c2 = c(3,3,3,3,1,1,1,1,2,2,2,3,2,2,1)
# Labels found but renamed correctly
c3 = c(1,1,1,1,2,2,2,2,3,3,3,1,3,3,2)
# Current output
tab1 <- table(c1,c2)
# c2
#c1 1 2 3
# 1 1 0 4
# 2 3 0 0
# 3 1 5 1
# Desired output
tab2 <- table(c1,c3)
# c3
#c1 1 2 3
# 1 4 1 0
# 2 0 3 0
# 3 1 1 5
In reality, c3
is not available. Is there an easy way to obtain c3
, tab2
from c2
, tab1
?
See Question&Answers more detail:
os