Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression Example #33

joshualeond opened this issue Sep 16, 2017 · 5 comments

Regression Example #33

joshualeond opened this issue Sep 16, 2017 · 5 comments


Copy link

Hi Thomas, thanks for your work here! I wanted to test the regression functionality similar to the python lime example here.

Everything seems to work correctly until the call to explain. Here is my reprex:

#> Loading required package: lattice
#> Loading required package: ggplot2

# load data
boston <- MASS::Boston

# Split up the data set
boston_test <- boston[1:100, 1:13]
boston_train <- boston[-(1:100), 1:13]
boston_lab <- boston[[14]][-(1:100)]

# Create Random Forest model on boston data
model_reg <- train(boston_train, boston_lab, method = 'rf')
#> randomForest 4.6-12
#> Type rfNews() to see new features/changes/bug fixes.
#> Attaching package: 'randomForest'
#> The following object is masked from 'package:ggplot2':
#>     margin

# Create an explainer object
explainer_reg <- lime(boston_train, model_reg)

# Explain new observation
explanation_reg <- explain(
  labels = NULL, 
  n_labels = 1, 
  n_features = 5
#> Warning in, explainer_reg, labels = NULL, :
#> "labels" and "n_labels" arguments are ignored when explaining regression
#> models
#> Error in y[1, ]: incorrect number of dimensions

I may be missing something obvious but I haven't discovered it yet. Also as a note, if I attempt to leave the labels and n_labels arguments out of the function call it throws an error. Thanks again.

Copy link

You seem to have stumbled upon a bug - I'll look into it. Thanks

@thomasp85 thomasp85 added the bug label Sep 20, 2017
@thomasp85 thomasp85 self-assigned this Sep 20, 2017
Copy link

Marouds commented Aug 9, 2018

Hi @joshualeond & @thomasp85,

I am having the exact same problem as Joshua with my random forest.
I don't know what to put as "labels" and "n_labels" in order to solve it?
Did you manage?

Thank you very much in advance.

Copy link

Hey @Marouds, I was able to run this example without any errors. This original bug resulted in the error:
#> Error in y[1, ]: incorrect number of dimensions

You're receiving this same error? Are you receiving this error using the example above or are you working with different data?

For a regression model you can remove the labels and n_labels arguments from the function call. Either way though, the explain() function should run without errors on this example.

Copy link

Marouds commented Aug 10, 2018

Hi @joshualeond, thank you very much for your quick reply!

I managed to run it in the end !! And indeed I was receiving the same error "#> Error in y[1, ]: incorrect number of dimensions". I added "drop=FALSE" when I split my data into training and testing dataset, and it worked!
(I might be using an old version of R)

Have a nice day

Copy link

Marouds commented Aug 10, 2018

I do have an issue with the visualization of the results, using plot_features().
It does not appear with colors and everything like it seems it should...
I don't know whether an addition packages was needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

3 participants