Getting variable of importance for ANN through leave-one-out cross validation

34 Views Asked by At

I want to get the VIPs for a ANN using LOO-CV. The code bellow works well when the vips is not being requested, but when I run the example leaving out a group it works well. I wonder why this is happening and how to fix this problem.

data(iris)
normalize <- function(x) {return((x - min(x)) / (max(x) - min(x)))}
iris_norm <- as.data.frame(lapply(iris[,-5], normalize))

FUN1 <- Vectorize(function(x, y) {
  train <- iris_norm[-x,]
  test <- iris_norm[x,]
  hd_layer <- round(as.numeric(nrow(train)/(1*(ncol(train) + 1 + 1))))
  fit <- neuralnet(y, data = train, 
                   hidden = hd_layer, 
                   threshold = 0.15,
                   stepmax = 1.5e+04)
  out <- list(results = neuralnet::compute(fit,test)$net.result*(max(iris[,3])-min(iris_norm[,3])) +  min(iris_norm[,3]), 
              vip = vip(fit, num_features = 4))
})

o1 <- outer(1:nrow(iris), FOAE, FUN1)

This is the type of error I am receiving:

Error in dim(robj) <- c(dX, dY) : 
  dims [product 602] do not match the length of object [1204]

The code above was modified from How to do a Leave One Out cross validation by group / subset?

0

There are 0 best solutions below