Skip to content

Instantly share code, notes, and snippets.

@monogenea
Created October 7, 2019 18:12
Show Gist options
  • Save monogenea/26e3e558263b13be39a3e14019886076 to your computer and use it in GitHub Desktop.
Save monogenea/26e3e558263b13be39a3e14019886076 to your computer and use it in GitHub Desktop.
# Split train/test with rsample
set.seed(100)
initSplit <- initial_split(X, prop = .9,
strata = "Y")
trainSet <- training(initSplit)
testSet <- testing(initSplit)
# Create 5-fold cross-validation, convert to caret class
set.seed(100)
myFolds <- vfold_cv(trainSet, v = 5, repeats = 5,
strata = "Y") %>%
rsample2caret()
ctrl <- trainControl(method = "cv",
selectionFunction = "oneSE")
ctrl$index <- myFolds$index
ctrl$indexOut <- myFolds$indexOut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment