thomasp85 / lime

Local Interpretable Model-Agnostic Explanations (R port of original Python package)
https://lime.data-imaginist.com/
Other
486 stars 110 forks source link

SVM - LIME - Error in glm.fit(x = x_fit, y = y, weights = weights, family = gaussian()) : #166

Closed CBRN-git closed 5 years ago

CBRN-git commented 5 years ago

Hello,

In R : After I got my binary classification SVM model using package e1071. I am trying to get local explanations using R LIME package but this error : Error in glm.fit(x = x_fit, y = y, weights = weights, family = gaussian()) : NAs in V(mu) after running the explain() function.

Here is the code :


model = svm(Label~., data=train,type="nu-classification",kernel="linear",probability = TRUE,gamma=0.5, cost=1,cross=0)

model_type.svm.formula = function(x, ...) {
  return("classification")
}

predict_model.svm.formula <- function(x, newdata, type, ...) {
  pred = predict(x,newdata,probability=TRUE) 
  switch(
    type,
    prob = as.data.frame(attr(pred, "probabilities"))
  )
}

explainer_svm = lime(train,model)
explanation_svm = explain(
  x = train, 
  explainer = explainer_svm, 
  n_permutations = 5000,
  dist_fun = "gower",
  kernel_width = .75,
  n_features = 5,
  feature_select = "auto",
  labels= c("1")
)

Can you please provide me any help ?

More informations can be found : https://stackoverflow.com/questions/58312042/svm-lime-error-in-glm-fitx-x-fit-y-y-weights-weights-family-gaus

Best regards, thank you.