I have the script below that works fine with the ctree model/party package. When I swap it with the NNET model/package, the varImp and plot(final model) throws an error. I was under the 'assumption' that the helper functions in the caret package worked with all supported models.
library(caret)
library(nnet)
#read in data
data = iris
#split data into training, test, and final test samples
trainIndex <- createDataPartition(data$Species, p=.80, list=F)
train = data[trainIndex,]
test = data[-trainIndex,]
#train and plot model fit
tree.fit = train(Species~., data=train, method="nnet")
varImp(tree.fit)
plot(tree.fit$finalModel)
#predict test data
tree.pred.test = predict(tree.fit, newdata=test)
confusionMatrix(tree.pred.test, test$Species)
> varImp(tree.fit)
nnet variable importance
variables are sorted by maximum importance across the classes
Error in data.frame(`NA` = character(0), `NA` = character(0), `NA` = character(0), :
row names supplied are of the wrong length
In addition: Warning message:
In format.data.frame(x, digits = digits, na.encode = FALSE) :
corrupt data frame: columns will be truncated or padded with NAs
> plot(tree.fit$finalModel)
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'