Cross-Validation

Machine LearningCVFree Lesson

Advertisement

Introduction

Cross-validation estimates model performance on unseen data. It helps prevent overfitting.

K-Fold CV

library(caret)

# 5-fold CV
trainControl(method = "cv", number = 5)

# 10-fold CV
trainControl(method = "cv", number = 10)

# Train with CV
model <- train(y ~ ., data = data,
               trControl = trainControl(method = "cv"))

Repeated CV

# Repeated 10-fold
trainControl(method = "repeatedcv",
             number = 10,
             repeats = 3)

Leave-One-Out CV

trainControl(method = "LOOCV")

Validation Set

# Simple split
trainControl(method = "holdout", p = 0.8)

Summary

Cross-validation provides reliable estimates. Use it to compare models and tune parameters.

Advertisement

Need Expert R Programming Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement