1

After obtaining accuracy metric from my keras binary classification model, I need know what the model made the predictions. So, I'm interested in variable importance. I use lime package.

library(lime)

explainer <- lime (
  x  = x_train, 
  model  = model_keras, 
  bin_continuous  = FALSE)

explanation <- explain (
    x_test[1:20,], # Show first 20 samples
    explainer    = explainer, 
    n_labels     = 1, 
    n_features   = 5) 

Explain function gives me the following error in py_get_attr_impl function: AttributeError: 'function' object has no attribute 'func_name'.

I have compiled keras model with R, but this Issue seems to be that error comes from Python version. Problems with Reticulate package?

Mario M.
  • 802
  • 11
  • 26

1 Answers1

1

It works with python 2.7 but generates error with python 3+.

Actually function attribute func_name was renamed in python 3+ to __name__.

lime package (models.R) has a line:

if (keras::get_layer(x, index = -1)$activation$func_name == 'linear')

I removed $func_name and the code worked for me. I suppose this is not the best workaround, however the possible solution that comes to mind:

if (keras::get_layer(x, index = -1)$activation$__name__ == 'linear')

did not work with R.

  • The full code was taken from here: http://www.business-science.io/business/2017/11/28/customer_churn_analysis_keras.html – Sergey Volkov Jul 31 '18 at 22:16