Zubnet AIAprenderWiki › Cross-Validation
Training

Cross-Validation

K-Fold CV, Leave-One-Out
Uma técnica para avaliar performance do modelo quando você não tem dados suficientes para um test set separado. K-fold cross-validation divide os dados em K partes iguais, treina em K−1 partes e avalia na parte restante, rotacionando K vezes para que cada ponto de dados seja usado para treinamento e avaliação. A pontuação média através dos K folds dá uma estimativa de performance mais confiável que um único split train/test.

Por que importa

Cross-validation é essencial quando dados são escassos — se você tem só 500 exemplos, separar 100 para teste significa treinar em 20% menos dados. Cross-validation usa todos os dados para treinamento e avaliação. Também te dá um intervalo de confiança (variância através de folds) em vez de um único número, te dizendo quão estável é a performance do seu modelo.

Deep Dive

5-fold CV: split data into 5 parts. Train on parts 1-4, evaluate on part 5. Then train on parts 1-3+5, evaluate on part 4. Repeat for all 5 folds. Average the 5 evaluation scores. The result is more reliable than a single 80/20 split because it's robust to the particular split — a "lucky" or "unlucky" test set can't skew the result. The standard deviation across folds indicates reliability.

Stratified K-Fold

For classification with imbalanced classes (rare disease: 5% positive, 95% negative), random splitting might put all positives in one fold. Stratified K-fold ensures each fold has the same class distribution as the full dataset. This prevents folds with no positive examples (useless for evaluation) and gives more reliable performance estimates for minority classes. Always use stratified K-fold for classification.

When Not to Use It

Cross-validation is computationally expensive (K times the training cost) and rarely used for large models. Fine-tuning a 7B model 5 times for 5-fold CV is impractical. For LLMs, a single held-out validation set is standard because: the datasets are large enough for reliable single-split evaluation, training is expensive, and the model's pre-trained representations make it less sensitive to the specific training split. Cross-validation is most valuable for small datasets with classical ML models.

Conceitos relacionados

← Todos os termos
ESC