0

I am running a neural net machine learning model in R using Caret's "nnet". I ran the train code with "importance= TRUE".

I need to show a list of the importances of the features that were included in the model. Not sure how to proceed. Any help is appreciated!

See code below. My outcome is in column 1 and the variables in columns 2 through 45.

str(data)
levels(data$outcome) <- c("no", "yes")
caret.control <- trainControl(method="repeatedcv", number=10, repeats=3)
model <- train(y=data[,1], x=data[,c(2:45)], method="nnet", trControl=caret.control, importance=TRUE)

I am looking at

varImp(model) 

but this gives an error message.

With this error message, I am researching it further:

names(model) 
names(model$modelInfo) 
names(model$modelInfo$varImp) 

The result from this is "NULL".

Anyone know how to fix this or has seen a similar error? Not sure how to see the list of features with "nnet" Caret package model.

phiver
  • 23,048
  • 14
  • 44
  • 56
ClareFG
  • 65
  • 1
  • 11
  • Hi Claire, did you train(..) finish without error? – StupidWolf Nov 12 '19 at 23:25
  • [`nnet`](https://www.rdocumentation.org/packages/nnet/versions/7.3-12/topics/nnet) does not have an importance argument. Nor does caret [`train`](https://www.rdocumentation.org/packages/caret/versions/6.0-84/topics/train). – missuse Nov 13 '19 at 13:29
  • (@ StupidWolf): Yes I finished without error. (@missuse): Your comment is not true. – ClareFG Nov 13 '19 at 19:09
  • Actually I figured out the error. In calling the "train(...)", you have to type out each of the variables individually instead of calling them in the shorthand way. From here, I called "varImp(model, scale=FALSE)" and got my variable importance list :) Such a simple difference but needed in order to see variable importances. Train statement and predictions will run with either method. – ClareFG Nov 13 '19 at 19:11
  • @ClareFG Does the `varImp(model, scale=FALSE)` call produce the expected result even when `train` is called without `importance=TRUE`? – missuse Nov 13 '19 at 21:24

0 Answers0