0Pricing
Data Science Academy · 课时

解读混淆矩阵

真正例、假正例、真负例和假负例

解读混淆矩阵 是 CoddyKit 上的免费 Data Science Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Data Science Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Data Science Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Beyond a Single Number

For classifiers, one accuracy score hides too much. The confusion matrix lays out exactly which predictions were right and which were wrong. 🧩

A Simple Grid

The matrix is a small grid: rows are the true classes, columns are the predicted ones. Each cell counts how often that pairing happened.

from sklearn.metrics import confusion_matrix
confusion_matrix(y_true, y_pred)

True Positives

A true positive is when the model says yes and the answer really is yes. These are the wins you want to maximize.

True Negatives

A true negative is when the model says no and the truth is also no. The model correctly left this case alone.

False Positives

A false positive is a false alarm: the model predicted yes, but the truth was no. Think of flagging a healthy patient as sick.

False Negatives

A false negative is a miss: the model said no while the truth was yes. Picture letting a real fraud slip through unnoticed.

Two Kinds of Mistakes

Notice the two error types differ in cost. A false positive and a false negative are rarely equal, so the matrix keeps them separate.

Where Accuracy Lives

Accuracy is just the correct cells over the total. It is the diagonal divided by everything, which is why it can mask rare errors.

accuracy = (TP + TN) / (TP + TN + FP + FN)

Read the Off-Diagonal

The most useful cells sit off the diagonal: they show where the model confuses one class for another, pointing to its weak spots.

See It as a Heatmap

For many classes, plot the matrix as a heatmap. Bright off-diagonal squares instantly reveal which labels get mixed up most.

from sklearn.metrics import ConfusionMatrixDisplay
ConfusionMatrixDisplay.from_predictions(y_true, y_pred)

Your Metric Foundation

Almost every classification metric is built from these four counts. Master the confusion matrix and the rest follow naturally.

Quick Check

Let's make sure each cell of the matrix is crystal clear.

Recap

The confusion matrix splits results into true and false, positive and negative. Those four counts power every classification metric. 🎯

常见问题解答

「解读混淆矩阵」课时是免费的吗?

是的 — 「解读混淆矩阵」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Data Science Academy 课程的其余内容,请升级到 CoddyKit PRO。 Data Science Academy 课程共包含 4 节课。

「解读混淆矩阵」这节课中我会学到什么?

真正例、假正例、真负例和假负例 你通过在浏览器中直接运行的动手代码来练习 Data Science Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Data Science Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Data Science Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「解读混淆矩阵」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Data Science Academy 课中编写并运行代码吗?

能。每节 Data Science Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 回归指标:MAE、MSE、R2
  2. 解读混淆矩阵
  3. 精确率、召回率和 F1
  4. ROC、AUC 和阈值
← 返回 Data Science Academy