You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TensorFlow混淆矩阵顺序确认:tf-slim生成6类矩阵的行列含义

Confusion Matrix Order in TF-Slim: Rows = True Labels, Columns = Predictions

Great question—this is a common point of confusion (pun intended) across ML tools! Let's clarify this for your TF-Slim use case:

1. Your Initial Statement Is Correct

TF-Slim's confusion matrix implementation aligns with TensorFlow's native tf.math.confusion_matrix behavior, which follows:

  • Rows = Ground Truth (True) Labels
  • Columns = Predicted Labels

Let's verify this with your matrix to make it concrete:

# Your 6-class confusion matrix
[
 [41, 2, 0, 0, 0, 0],  # True class 0: 41 correct, 2 misclassified as class 1
 [1, 11, 4, 1, 0, 0],  # True class 1: 11 correct, 1 misclassified as 0, 4 as 2, 1 as 3
 [0, 1, 12, 0, 0, 0],  # True class 2: 12 correct, 1 misclassified as class 1
 [0, 0, 0, 22, 1, 0],  # True class 3: 22 correct, 1 misclassified as class 4
 [0, 0, 0, 0, 7, 0],   # True class 4: 7 correct, no misclassifications
 [0, 0, 0, 0, 0, 20]   # True class 5: 20 correct, no misclassifications
]

Each row sums to the total number of samples in that true class (e.g., row 0 sums to 43, which is 41+2—total true class 0 samples). Each column sums to the total number of predictions for that class (e.g., column 1 sums to 2+11+1=14—total predictions for class 1). This matches the "rows = true, columns = predicted" structure perfectly.

2. Why Do Some Sources Say the Opposite?

The mix-up happens because there’s no universal standard across all ML libraries or custom code:

  • Some older tools or hand-rolled implementations swap the axes (columns = true labels, rows = predictions)
  • Certain visualization libraries might flip the matrix for display readability
  • Always double-check the documentation of the specific tool you’re using to confirm the order

For TF-Slim specifically, since it’s a lightweight wrapper around TensorFlow’s core APIs, you can trust that it uses the same axis order as TensorFlow’s official confusion matrix function.


内容的提问来源于stack exchange,提问作者Jame

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:35:23