Separe entrenamiento, validación y prueba
Por qué necesita tres conjuntos y no uno
Separe entrenamiento, validación y prueba es una lección gratuita de Deep Learning Academy en CoddyKit. Esta es la lección 1 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 Deep Learning Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Deep Learning Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
One Pile Is Not Enough
If you train and judge a model on the same data, you only learn that it memorized those rows. To trust it, you must split your data into separate roles.
Meet the Training Set
The training set is the data your model actually learns from. Its weights are nudged again and again to fit exactly these examples well.
Meet the Validation Set
The validation set is held back during training and checked along the way. It tells you how the model does on data it has never updated on.
Meet the Test Set
The test set is touched once, at the very end. It gives an honest, final score after every choice has already been made.
Why Validation Is Separate
You tune knobs like learning rate by watching validation results. That quietly leaks the validation set into your choices, so it can no longer be a clean final judge.
The Test Set Stays Sealed
Because validation guided your decisions, you need one untouched pile for the truth. Keep the test set sealed until you are completely done.
A Common Split
A typical starting point is roughly 80/10/10: most data for training, smaller slices for validation and test. Adjust based on how much data you have.
Split with random_split
PyTorch gives you random_split to carve a dataset into pieces by length. It shuffles which samples land in each set for you.
from torch.utils.data import random_split
train, val, test = random_split(ds, [800, 100, 100])Seed for Reproducible Splits
The split is random, so set a seed if you want the same pieces every run. That keeps experiments comparable across sessions.
g = torch.Generator().manual_seed(42)
train, val, test = random_split(ds, [800, 100, 100], generator=g)Stratify for Balance
With rare classes, a plain random split may leave some out. Stratifying keeps each set's class mix close to the original so scores stay meaningful.
Never Peek at Test
The golden rule is simple: do not let the test set shape any decision. The moment it does, your final number stops being trustworthy.
Quick Check
Which set should you look at only once, at the very end?
Recap
Three sets, three jobs: training teaches the model, validation guides your tuning, and test gives the final honest score. Keep test sealed until the end. 🎯
Preguntas frecuentes
¿La lección «Separe entrenamiento, validación y prueba» es gratis?
Sí — el texto completo de «Separe entrenamiento, validación y prueba» 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 Deep Learning Academy, actualiza a CoddyKit PRO. El curso de Deep Learning Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Separe entrenamiento, validación y prueba»?
Por qué necesita tres conjuntos y no uno Practicas Deep Learning 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 Deep Learning Academy?
No se requiere experiencia previa. Deep Learning 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 1 de 4.
¿Cuánto tiempo toma la lección «Separe entrenamiento, validación y prueba»?
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 Deep Learning Academy?
Sí. Cada lección de Deep Learning 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
- Separe entrenamiento, validación y prueba
- Un bucle de épocas con validación
- Guardar y cargar con state_dict
- Early stopping según la pérdida de validación