Skip to content

Instantly share code, notes, and snippets.

@wdkrnls
Created November 25, 2015 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wdkrnls/1373b1bc81156b29786d to your computer and use it in GitHub Desktop.
Save wdkrnls/1373b1bc81156b29786d to your computer and use it in GitHub Desktop.
#' My function for doing cross validation (creating the splits before hand)
xvalidate <- function(f, formula, data, bin, ...) {
fold <- length(bin)
xs <- seq.int(1, fold)
lapply(xs, function(x) {
train <- data[unlist(bin[-x]),]
test <- data[bin[[x]],]
model <- f(formula, data = train, ...)
predict(model, newdata = test)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment