ROC, AUC y umbrales
Evaluar la calidad de la clasificación por rangos de corte.
ROC, AUC y umbrales es una lección gratuita de Data Science Academy en CoddyKit. Esta es la lección 4 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.
Models Output Probabilities
Most classifiers do not just say yes or no. They give a probability, like 0.73, and you decide where to draw the line. 🎚️
probs = model.predict_proba(X)[:, 1]The Decision Threshold
A threshold turns a probability into a label. Above it means positive, below means negative. The default 0.5 is just one choice.
y_pred = probs >= 0.5Moving the Line
Lower the threshold and you catch more positives but raise false alarms. Raise it and you are stricter but miss more. Each setting trades off.
Two Rates to Track
As the threshold slides, watch the true positive rate against the false positive rate. Together they describe the model at every cutoff.
The ROC Curve
The ROC curve plots true positive rate versus false positive rate across all thresholds, showing the full trade-off in one picture.
from sklearn.metrics import roc_curve
fpr, tpr, thr = roc_curve(y_true, probs)Reading the Shape
A curve that hugs the top-left corner is excellent: high catch rate with few false alarms. A diagonal line means random guessing.
Area Under the Curve
AUC squeezes the whole ROC curve into one number: the area beneath it. It summarizes performance across every threshold at once.
from sklearn.metrics import roc_auc_score
roc_auc_score(y_true, probs)What AUC Means
AUC of 1.0 is perfect, 0.5 is coin-flip random. Read it as the chance the model ranks a true positive above a true negative.
Threshold-Free Comparison
Because AUC ignores any single cutoff, it is great for comparing models. The winner ranks positives ahead of negatives more often.
Then Pick a Threshold
AUC picks the model, but you still set the threshold for real use, tuning it to favor recall or precision as the problem demands.
When to Prefer PR Curves
On very imbalanced data, ROC can look rosy. A precision-recall curve often tells the harder truth about rare-class performance.
Quick Check
Let's confirm what AUC really tells you about a classifier.
Recap
The threshold turns probabilities into labels, the ROC curve shows every trade-off, and AUC scores the whole curve at once. 🎯
Preguntas frecuentes
¿La lección «ROC, AUC y umbrales» es gratis?
Sí — el texto completo de «ROC, AUC y umbrales» 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 «ROC, AUC y umbrales»?
Evaluar la calidad de la clasificación por rangos de corte. 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 4 de 4.
¿Cuánto tiempo toma la lección «ROC, AUC y umbrales»?
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
- Métricas de regresión: MAE, MSE y R2
- Descifrar la matriz de confusión
- Precisión, exhaustividad y F1
- ROC, AUC y umbrales