title: Shapley values for glmnet using R's iml package
body: <p>I'm unable to use the <code>iml</code> package in R to find shapley values for <code>glmnet</code> models.</p>
  <p>It seems like the problem might be related to the fact that <code>glmnet()</code> and <code>predict.glmnet()</code> expect matrices, while the <code>x.interest</code> argument in <code>iml::Shapley$new()</code> expects a data frame, and so something is being incorrectly converted, but I'm not sure.</p>
  <p>The most reasonable thing I've tried is below. Because of the following note in the <code>iml::Predictor()</code> documentation, I make sure my prediction function returns estimated probabilities for both classes: &quot;Note: In case of classification, the model should return one column per class with the class probability.&quot;</p>
  <pre><code>library(dplyr)
  library(iml)
  library(glmnet)
  df &lt;- filter(iris, Species != 'setosa')
  X &lt;- as.matrix(select(train, -Species))
  y &lt;- droplevels(df$Species)
  fit &lt;- glmnet(X, y, family = 'binomial', lambda = 0.03)
  
  predfun &lt;- function(model, newdata) {
    preds &lt;- predict(model, as.matrix(newdata), type = 'response') # probabilities
    return(cbind(1 - preds, preds)) # for both classes 
  }
  
  # Pass data frames, as requested
  mod &lt;- Predictor$new(fit, as.data.frame(X), predict.function = predfun) 
  shapley &lt;- Shapley$new(mod, x.interest = as.data.frame(X[1, ]))
  </code></pre>
  <p>This gives me the following: <code>Error in predict.glmnet(model, as.matrix(newdata), type = &quot;response&quot;): The number of variables in newx must be 4</code></p>
  <p>I'm not really sure what is being passed to <code>predict.glmnet()</code> that doesn't have four variables (it doesn't seem to have to do with an intercept from things I've tried). I've looked at the source code for <code>Shapley$new()</code> and also stepped for quite a while through a call via <code>browser()</code> but wasn't able to come up with anything useful.</p>
  <p>Any ideas?
  Thank you!</p>