Skip to content

A ‘leave-one-out’ function

September 19, 2013

Here’s a little function I often put at the beginning of R scripts in which I’m going to do a lot of cross validation:
loo <- function(data) lapply(1:nrow(data), function(i) data[-i,])
It usually works pretty well just as is, but sometimes needs additional bells and whistles (e.g. K-fold CV). Its also stupid slow for big data sets, but its some nice sugar for most of my CV problems.

No comments yet

Leave a comment