thomasp85 / lime

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

How to change discretization using mdlp #83

Closed DiliSR closed 6 years ago

DiliSR commented 6 years ago

Thank you for your wonderful implementation in R.

I just have a question when using mdlp() when discritize. I need to discretize column wise. But when using mdlp function it does not allow that. Could you please help me for that.

mdlp() doean't allow to discritize one column at a time.

explainer$bin_cuts <- setNames(lapply(seq_along(x), function(i) {
    if (explainer$feature_type[i] %in% c('numeric', 'integer')) {
      if (quantile_bins) {
        bins <- quantile(x[[i]], seq(0, 1, length.out = n_bins + 1), na.rm = TRUE)
        bins[!duplicated(bins)]

      }
      else if(mdlp){
        disc<-mdlp(x[[i]])
        bins <- disc$cutp
        bins[!duplicated(bins)]

      }

      else {
        d_range <- range(x[[i]], na.rm = TRUE)
        seq(d_range[1], d_range[2], length.out = n_bins + 1)
      }
    }
  }), names(x))
thomasp85 commented 6 years ago

I’m unfamiliar with mdlp- can you please provide a fully reproducible example

DiliSR commented 6 years ago
library(dprep)
library(discretization)
data("iris")

disc<- mdlp(as.data.frame(iris[,1]))
bins<-disc$cutp
print(bins)

This doesn't wok But this work

library(dprep)
library(discretization)
data("iris")

disc<- mdlp(as.data.frame(iris))
bins<-disc$cutp
print(bins)
DiliSR commented 6 years ago

Suppose if I need to discretize only one column of the dataset. Then this happens.

thomasp85 commented 6 years ago

There seems to be an error in the discretization package that forgets to not drop the dimension in single column data.frames

I suggest you bring this to the developers of the discretization package as this has nothing to do with lime...