I am working on neural networks for a regression problem in R using packages like nnet
, caret
etc. I have split my data into train, validation and test. My doubt is does the train()
function in caret
package for R takes care for validation set also.
From what I understand, After training the nnet
model, you need to keep checking with validation data set, to avoid overfitting or overlearning i.e restricting the number of iterations. Then we have to tune for the decay parameters and size of hidden layers and finally apply it on the test data set.
Is there anything wrong with the understanding? FYI. Here is the code that I am implementing
Y=read.csv(file="./dolcan.csv",header=T)
ratio=as.integer(0.5*nrow(Y))
ratio1=as.integer(0.75*nrow(Y))
traindata=Y[(1:ratio),c(2:ncol(Y))]
valdata=Y[(ratio:ratio1),c(2:ncol(Y))]
testdata=Y[((ratio1+1):nrow(Y)),c(2:ncol(Y))]
## Train the network and tuning the number of nodes and decay
maxout= max(traindata[,1]) # to scale the output
mygrid <- expand.grid(.decay=c(0.5, 0.1), .size=c(3,4,5))
nnetfit <- train(dolcan/maxout ~ ., data=traindata, method="nnet", maxit=1000, tuneGrid=mygrid, trace=F)
nnetfit