Zubnet AI学习Wiki › Cross-Validation
Training

Cross-Validation

K-Fold CV, Leave-One-Out
在没有足够数据做单独测试集时评估模型性能的技术。K-fold cross-validation 把数据切成 K 等份,在 K−1 份上训练、在剩下的一份上评估,轮换 K 次,让每个数据点都用于训练和评估。K 个 fold 的平均分数比单次 train/test 切分给出更可靠的性能估计。

为什么重要

Cross-validation 在数据稀少时必不可少 — 如果你只有 500 个样本,拿 100 个做测试意味着训练少 20% 数据。Cross-validation 让所有数据用于训练和评估。它还给你置信区间(fold 间的方差)而不是单个数字,告诉你模型性能多稳定。

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.

相关概念

← 所有术语
ESC