I need to use varImp function on neural network model created by nnet method via caret.
The code:
#Load Packages
require(quantmod)
require(nnet)
require(caret)
#Creating data
T <- seq(0,20,length=200)
y <- 1 + 3*cos(4*T+2) +.2*T^2 + rnorm(200)
dat <- data.frame( y, x1=Lag(y,1), x2=Lag(y,2),x3=Lag(y,3))
dat <- dat[4:length(dat[,1]),]
names(dat) <- c('y','x1','x2','x3')
set.seed(100)
podzial <- createDataPartition(y, p = 3/4, list = FALSE)
zucz<-dat[podzial,]
ztest<-dat[-podzial,]
# Train control
ctrl <- trainControl(method = "LGOCV",p=0.7)
#Training
model <- train(y ~ x1+x2 , zucz, method='nnet', linout=TRUE, trace=F,maxit=100,skip=T,
tuneGrid=expand.grid(.size=c(10),.decay=c(0,0.1,0.001,0.0001)),
trControl = ctrl,
preProcess = c("range"))
varImp(model,scale=F)
When I try to use varImp the error occurs:
Error in i2h[hidden, input] <- abeta[grep(label, nms, fixed = TRUE)] :
number of items to replace is not a multiple of replacement length
I have done several test with diferent number of neurons. It appears that error occurs when number of neurons (size parameter) is bigger than 9. How to fix it?
hidden * input) of the output "region" is not a match for the length of whatabetais putting out. You'll need to fix that. - Carl Witthoft