Separare training, validation e test
Scopra perché servono tre set, non uno solo
Separare training, validation e test è una lezione Deep Learning Academy gratuita su CoddyKit. Questa è la lezione 1 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 Deep Learning Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Deep Learning Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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. 🎯
Domande Frequenti
La lezione «Separare training, validation e test» è gratuita?
Sì — il testo completo di «Separare training, validation e test» è 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 Deep Learning Academy, passa a CoddyKit PRO. Il corso Deep Learning Academy include 4 lezioni in totale.
Cosa imparerò in «Separare training, validation e test»?
Scopra perché servono tre set, non uno solo Eserciti Deep Learning 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 Deep Learning Academy?
Non è richiesta alcuna esperienza precedente. Deep Learning 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 1 di 4.
Quanto tempo richiede la lezione «Separare training, validation e test»?
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 Deep Learning Academy?
Sì. Ogni lezione Deep Learning 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
- Separare training, validation e test
- Un ciclo per epoche con validazione
- Salvare e caricare con state_dict
- Early stopping sulla loss di validazione