Hello and thanks in advance. I'm using caret
to cross validate a neural-network from the nnet
package. In the method
parameter for the trainControl
function I can specify my cross-validation type, but all of these choose the observations at random to cross-validate against. Is there anyway I can use caret to cross-validate on specific observations in my data by either an ID or a hard-coded parameter? For example here's my current code:
library(nnet)
library(caret)
library(datasets)
data(iris)
train.control <- trainControl(
method = "repeatedcv"
, number = 4
, repeats = 10
, verboseIter = T
, returnData = T
, savePredictions = T
)
tune.grid <- expand.grid(
size = c(2,4,6,8)
,decay = 2^(-3:1)
)
nnet.train <- train(
x = iris[,1:4]
, y = iris[,5]
, method = "nnet"
, preProcess = c("center","scale")
, metric = "Accuracy"
, trControl = train.control
, tuneGrid = tune.grid
)
nnet.train
plot(nnet.train)
Suppose I wanted to add another column CV_GROUP
to the iris
data frame and I wanted caret to cross-validate the neural-network on observations with a value of 1
for that column:
iris$CV_GROUP <- c(rep.int(0,times=nrow(iris)-20), rep.int(1,times=20))
Is this possible with caret
?