Skip to content

Instantly share code, notes, and snippets.

@timcdlucas
Created February 14, 2020 16:07
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 timcdlucas/94ef8d8cb652f7f35403cd6ade23da49 to your computer and use it in GitHub Desktop.
Save timcdlucas/94ef8d8cb652f7f35403cd6ade23da49 to your computer and use it in GitHub Desktop.
Get the out of sample predictions from the best set of hyperparameters
get_preds <- function(t){
stopifnot(inherits(t, 'train'))
oos <- t$pred %>% arrange(rowIndex)
row_matches <- sapply(1:length(t$bestTune), function(x) oos[, names(t$bestTune)[x]] == t$bestTune[[x]])
best_rows <- rowMeans(row_matches) == 1
d <- oos[best_rows, ]
return(as.numeric(d$pred))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment