The real wordsPractical
Step 2: the split, two ways
library(caTools)
split <- sample.split(mtcars$am, SplitRatio = 0.7)
train <- subset(mtcars, split == TRUE)
test <- subset(mtcars, split == FALSE)
Or, in the k-NN doc, using rsample.
data_split <- initial_split(diabetes_norm, prop = 0.7, strata = diabetes)
train_data <- training(data_split)
test_data <- testing(data_split)
sample.split returns a TRUE/FALSE vector, which is then used to cut the data both ways.