0

I'm trying to train a neural network on candidatesTestData, a 20177 x 14 matrix, while trying to follow the procedure listed here: this answer I am trying to avoid over-fitting the training data. This is what I have tried so far:

returnNet <- NULL
currMax <- 40
for(i in 1:10) {
  validationData <- sample_n(candidatesTrainingData, 20)
  trainingData <- setdiff(candidatesTrainingData, validationData)
  temp <- nnet(yield ~ ., data=trainingData, size = 6, linout=TRUE, skip=TRUE, MaxNWts = 10000)
  validationPrediction <- predict(temp, validationData[1:length(names(validationData))-1])
  errorVector <- abs(validationData$yield - validationPrediction)
  if ( min(errorVector, na.rm=TRUE) < 5 & mean(errorVector, na.rm=TRUE) < currMax ) {
    currMax <- mean(errorVector, na.rm=TRUE)
    returnNet <- temp
  }
}
return(returnNet)

In 10 minutes 60 iterations have completed for the first Neural Network. Is there any way this can be sped up i.e. improve the algorithmic run time?

Community
  • 1
  • 1
  • Where do `sample_n` and `nnet` come from? Please provide a source or a link to these functions. Also: Why is there a `return(neuralNet)` when there is no function to end? Could it be that `neuralNet` should be `returnNet` instead (`neuralNet` is defined as `NULL` and never changed)? – SimonG Jun 24 '16 at 14:22
  • `sample_n` comes from the `dplyr` package, while `nnet` comes from the `nnet` package. Would having the return statement significantly slow down the code? Also, `neuralNet` at the very top is a typo. Fixed that in the main qn. – Ananth Ravi Kumar Jun 24 '16 at 14:25
  • Usually, calling `return` outside of a function simply gives an error. I don't see how it would affect speed. – SimonG Jun 24 '16 at 15:13
  • What version of R are you using? There is a version of R -microsoft R that can harness multicore performance, also packages like doSNOW – Dinesh.hmn Jun 24 '16 at 15:33

0 Answers0