![]() |
VOOZH | about |
LOOCV (Leave-One-Out Cross-Validation) is a model evaluation technique used to assess the performance of a machine learning model on small datasets. In LOOCV, one observation is used as the test set while the rest form the training set. This process is repeated for each data point in the dataset, resulting in n training-testing cycles, where n is the number of observations. The overall accuracy is averaged across all iterations.
In Leave-One-Out Cross-Validation (LOOCV), each individual observation serves once as the validation set, while the remaining n-1 observations are used for training. Instead of refitting the model n times, LOOCV for linear models can be computed efficiently using the following formula:
LOOCV Error
Where:
We are going to perform a Leave-One-Out Cross Validation (LOOCV) on the Hedonic dataset to evaluate the performance of linear regression models with increasing polynomial degrees.
We are loading the Ecdat package, which contains the Hedonic dataset with information on housing prices, and the boot package, which provides tools for resampling methods, including Leave-One-Out Cross Validation (LOOCV). We will then check the structure of the Hedonic dataset.
Output:
We are fitting a linear regression model to predict age and performing LOOCV to evaluate its performance.
Output:
We are extracting the Mean Squared Error (MSE) from the LOOCV to evaluate model performance.
Output:
Mean Squared error for the model is: 250.2985 250.2856
We are fitting polynomial models with increasing degrees and performing LOOCV to evaluate their performance.
Output:
Mean Squared error for the model is: 250.2985 252.4706 254.7776 299.5546 455.6091
Disadvantage of LOOCV : Training the model N times leads to expensive computation time if the dataset is large.