R: LIME for variable importance with KERAS takes forever to run

369 views Asked by At

I am running a KERAS neural network in R - which works!

The network that I have estimated has 1.441 parameters.

22 Input variables and 11580 observations in the training set and 19.659 in the test set.

Now I trying to investigate what variables are important for the network. To do this I am trying with the LIME package.


library(lime)

keras.engine.sequential.Sequential <- function(x,...) {
  "regression"
}

predict_model.keras.engine.sequential.Sequential <- function (x, newdata, type, ...) {
  pred <- predict(object = x, x = as.matrix(newdata))
  data.frame (Positive = pred, Negative = 1 - pred) }

predict_model (x       = model_nn, 
               newdata = (q), 
               type    = 'raw')



explainer <- lime::lime(
  x= x,
  model = model_nn, 
  bin_continous = FALSE
)



explanation <- explain (
    q, # Just to show first 10 cases
    explainer    = explainer, 
   # n_labels     = 1, # explaining a `single class`(Polarity)
    n_features   = 2, # returns top four features critical to each case
    kernel_width = 0.5) # allows us to increase model_r2 value by shrinking the localized evaluation.

Where q is my testing set, defined as a data.frame, and x is that training test data set as a data.frame.

This takes a really long time to run, so long that I have to stop it..

Is this real? Or did I make a mistake in the code?

0

There are 0 answers