How to model a neural network through the use of caret, R

11,247

You need to use the option linout = TRUE for the nnet function:

model <- train(RT..seconds.~., data = cadets, 
               method = "nnet", trControl = ctrl,
               linout = TRUE)

If you do not, a sigmoidal activation function is used and all of the predictions will be constrained to be on [0, 1].

Share:
11,247
user2062207
Author by

user2062207

Updated on June 04, 2022

Comments

  • user2062207
    user2062207 almost 2 years

    So I have a dataset that I've been performing machine learning algorithms on. I've performed MLR, stepwise regression, SVM and Random Forest on a dataset that is 180 x 160. I'm modelling one variable against 159 other variables, with 179 cases. It's all regression modelling. I've been using the caret package in which I use the train function to do 10 fold cross validation 10 times with the different machine learning algorithms. I was told to read up a paper that had used neural network models instead and got better results, so I've been trying to find a way of doing the same thing but with a neural network model instead.

    I've had a look at doing the following:-

    model <- train(RT..seconds.~., data = cadets, method = "AMORE", trControl = ctrl)
    

    but it doesn't work. I was told that it wouldn't work as the train function does not have the AMORE packaged wrapped yet. So I looked to use nnet instead:-

    model <- train(RT..seconds.~., data = cadets, method = "nnet", trControl = ctrl)
    

    which worked. However, the RMSE value I got was 171, and when I looked at my predicted vs observed values, the predicted values were all just 1s and 0.9999s. Does anyone know what I'm doing wrong?

    thanks!

  • user2062207
    user2062207 about 10 years
    Thank you, it seems to have work! Although the answers I get are like grouped (like it deviates between 8 different numbers) but hell it still works, thanks