Decodificare la matrice di confusione
Veri e falsi positivi e negativi.
Decodificare la matrice di confusione è una lezione Data Science Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Data Science Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Data Science Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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. 🎯
Domande Frequenti
La lezione «Decodificare la matrice di confusione» è gratuita?
Sì — il testo completo di «Decodificare la matrice di confusione» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Data Science Academy, passa a CoddyKit PRO. Il corso Data Science Academy include 4 lezioni in totale.
Cosa imparerò in «Decodificare la matrice di confusione»?
Veri e falsi positivi e negativi. Eserciti Data Science Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Data Science Academy?
Non è richiesta alcuna esperienza precedente. Data Science Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Decodificare la matrice di confusione»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Data Science Academy?
Sì. Ogni lezione Data Science Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Metriche di regressione: MAE, MSE, R2
- Decodificare la matrice di confusione
- Precision, recall e F1
- ROC, AUC e soglie