-2

Could someone please validate the algorithm for 10 fold cross validation?

I do not want to use the cut function as I thought of this intuition

1) Find length of the dataframe, n. 2) No: instances in test set size = floor(n/10) 3) loop over i from 1:10 4) Create folds by taking the indices; a) indices=1:size of the data frame for first fold b) indices=((i - 1) * size + 1):(i * size) for all the other folds except the 10th c) indices=((i - 1) * size + 1):(n) for the 10th fold

  test=df[indices,]
  train=df[-indices,]

5) Train the model and find the MSE for each fold.

  • You need [to make your example reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#5963610) – alistaire Feb 09 '18 at 22:36

1 Answers1

-1

Consider the Caret package. It automatically divides datasets into training and testing. See here:

Caret Package

Example:

library(caret)
set.seed(325)
trainIndex <- createDataPartition(df$"Yourdata", p = .5, 
                                  list = FALSE, 
                                  times = 1)

The p value is the percentage of the data that goes to training.

The times valuespecifies how many partitions you want to create.

The createFolds command of the Caret package can be used to create balanced cross validation groupings.

benschbob91
  • 155
  • 12