Decodificando a matriz de confusão
Verdadeiros e falsos positivos e negativos.
Decodificando a matriz de confusão é uma aula grátis de Data Science Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Data Science Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Data Science Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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. 🎯
Perguntas Frequentes
A aula “Decodificando a matriz de confusão” é grátis?
Sim — o texto completo de “Decodificando a matriz de confusão” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Data Science Academy, atualize para CoddyKit PRO. O curso de Data Science Academy inclui 4 aulas no total.
O que vou aprender em “Decodificando a matriz de confusão”?
Verdadeiros e falsos positivos e negativos. Você pratica Data Science Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Data Science Academy?
Nenhuma experiência prévia é necessária. Data Science Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.
Quanto tempo leva a aula “Decodificando a matriz de confusão”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Data Science Academy?
Sim. Cada aula de Data Science Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Métricas de regressão: MAE, MSE e R2
- Decodificando a matriz de confusão
- Precisão, revocação e F1
- ROC, AUC e limiares