πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Cross-Validation: Theory and Optimality

Machine LearningCross-Validation: Theory and Optimality🟒 Free Lesson

Advertisement

Cross-Validation: Theory and Optimality

Module: Machine Learning | Difficulty: Advanced

k-Fold CV Risk

Leave-One-Out (LOO)

GCV (Generalized Cross-Validation)

Bias-Variance of CV

MethodBiasComputationRecommended
LOOLow modelsSmall n
5-FoldMedium5 modelsMedium n
10-FoldLow-Medium10 modelsLarge n
.632+Low1 model + bootstrapVery large n
import numpy as np
from sklearn.model_selection import KFold

def cross_validate(model, X, y, k=10, scoring='mse'):
    kf = KFold(n_splits=k, shuffle=True, random_state=42)
    scores = []
    for train_idx, val_idx in kf.split(X):
        model.fit(X[train_idx], y[train_idx])
        pred = model.predict(X[val_idx])
        scores.append(((y[val_idx] - pred)**2).mean())
    return np.mean(scores), np.std(scores)

Research Insight: 10-fold CV has been shown to have the lowest MSE as an estimator of true prediction error, balancing bias (from fold size) and variance (from number of folds).

Need Expert Machine Learning Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement