我需要varImp
在由 nnet 方法通过插入符号创建的神经网络模型上使用函数。
编码:
#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)
当我尝试使用varImp
时出现错误:
Error in i2h[hidden, input] <- abeta[grep(label, nms, fixed = TRUE)] :
number of items to replace is not a multiple of replacement length
我用不同数量的神经元做了几次测试。当神经元数量(大小参数)大于 9 时,似乎会发生错误。如何解决?