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.

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: