To perform **leave-one-out cross-validation** (**LOOCV**) to limit overfitting, perform the following steps:

- Read the data:

> bh <- read.csv("BostonHousing.csv")

- Create the two functions shown as follows; we show line numbers for discussion:

1 rdacb.loocv.reg <- function(df) { 2 mean.sqr.errs <- sapply(1:nrow(df), rdacb.loocv.reg.iter, df) 3 list("mean_sqr_errs"= mean.sqr.errs, "overall_mean_sqr_err" = mean(mean.sqr.errs), "std_dev_mean_sqr_err" = sd(mean.sqr.errs)) 4 } 5 rdacb.loocv.reg.iter <- function(k, df) { 6 mod <- lm(MEDV ~ ., data = df[-k, ] ) 7 pred <- predict(mod, df[k,]) 8 sqr.err <- (pred - df[k, "MEDV"])^2 9 }

- With the preceding two functions in place, you can run LOOCV as follows (this runs 506 linear regression ...