0Pricing
Data Science Academy · Lección

Descifrar la matriz de confusión

Verdaderos y falsos positivos y negativos.

Descifrar la matriz de confusión es una lección gratuita de Data Science Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Data Science Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Data Science Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en 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. 🎯

Preguntas frecuentes

¿La lección «Descifrar la matriz de confusión» es gratis?

Sí — el texto completo de «Descifrar la matriz de confusión» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Data Science Academy, actualiza a CoddyKit PRO. El curso de Data Science Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Descifrar la matriz de confusión»?

Verdaderos y falsos positivos y negativos. Practicas Data Science Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Data Science Academy?

No se requiere experiencia previa. Data Science Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.

¿Cuánto tiempo toma la lección «Descifrar la matriz de confusión»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Data Science Academy?

Sí. Cada lección de Data Science Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Métricas de regresión: MAE, MSE y R2
  2. Descifrar la matriz de confusión
  3. Precisión, exhaustividad y F1
  4. ROC, AUC y umbrales
← Volver a Data Science Academy