如何对混淆矩阵中的列进行排序?
How to order columns in a confusion matrix?
我有一个混淆矩阵,如下所示:
[[110, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 12, 0],
[ 0, 107, 0, 0, 0, 0, 0, 62, 12, 0, 0, 0, 1, 0],
[ 0, 0, 70, 1, 10, 0, 0, 0, 0, 0, 0, 0, 213, 34,],
[ 0, 0, 110, 14, 14, 0, 0, 0, 0, 0 , 0, 0 60 55],
[ 0, 0, 40, 0, 178, 3, 1, 0, 3, 7, 7, 0, 256, 31],
[ 0, 0 65, 14, 3, 73, 0, 0, 0, 0, 0, 0, 4, 82],
[ 0, 0, 0, 0, 0, 0, 41, 2, 242, 2, 0, 0, 75, 5],
[ 2, 1, 0, 1, 0, 0, 1, 88, 112, 0, 0, 0, 1, 29],
[ 3, 7 0, 2, 0, 0 78, 43, 14, 58, 0, 1, 20, 26],
[ 0, 0, 0, 0, 31, 0, 0, 4, 0, 517, 0, 0, 238, 1],
[ 13, 0, 4, 0, 0, 0, 2, 94, 128, 1, 49, 31, 204, 18],
[ 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 184, 1, 9],
[ 0, 0, 8, 0, 0, 0, 0, 0, 2, 0, 0, 0, 130, 7],
[ 0, 0, 0 0, 0, 0 0, 0, 17, 0, 0, 0, 51, 79]]
class 标签是这样的:
[0,1,10,11,12,13,2,3,4,5,6,7,8,9]
如何重新排序混淆矩阵,以便 class 标签按顺序排列,如下所示:
[0,1,2,3,4,5,6,7,8,9,10,11,12,13]
让我们尝试切片:
new_orders = np.argsort(classes)
cm[new_orders][:,new_orders]
我有一个混淆矩阵,如下所示:
[[110, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 12, 0],
[ 0, 107, 0, 0, 0, 0, 0, 62, 12, 0, 0, 0, 1, 0],
[ 0, 0, 70, 1, 10, 0, 0, 0, 0, 0, 0, 0, 213, 34,],
[ 0, 0, 110, 14, 14, 0, 0, 0, 0, 0 , 0, 0 60 55],
[ 0, 0, 40, 0, 178, 3, 1, 0, 3, 7, 7, 0, 256, 31],
[ 0, 0 65, 14, 3, 73, 0, 0, 0, 0, 0, 0, 4, 82],
[ 0, 0, 0, 0, 0, 0, 41, 2, 242, 2, 0, 0, 75, 5],
[ 2, 1, 0, 1, 0, 0, 1, 88, 112, 0, 0, 0, 1, 29],
[ 3, 7 0, 2, 0, 0 78, 43, 14, 58, 0, 1, 20, 26],
[ 0, 0, 0, 0, 31, 0, 0, 4, 0, 517, 0, 0, 238, 1],
[ 13, 0, 4, 0, 0, 0, 2, 94, 128, 1, 49, 31, 204, 18],
[ 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 184, 1, 9],
[ 0, 0, 8, 0, 0, 0, 0, 0, 2, 0, 0, 0, 130, 7],
[ 0, 0, 0 0, 0, 0 0, 0, 17, 0, 0, 0, 51, 79]]
class 标签是这样的:
[0,1,10,11,12,13,2,3,4,5,6,7,8,9]
如何重新排序混淆矩阵,以便 class 标签按顺序排列,如下所示:
[0,1,2,3,4,5,6,7,8,9,10,11,12,13]
让我们尝试切片:
new_orders = np.argsort(classes)
cm[new_orders][:,new_orders]