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

error in ceteris_paribus.default with a response with several labels #27

Closed
Quentin62 opened this issue Jun 26, 2019 · 1 comment
Closed
Labels

Comments

@Quentin62
Copy link

@Quentin62 Quentin62 commented Jun 26, 2019

When you have a response variable with several labels and provide a data.frame with several rows in ceteris_paribus, it returns an error like this:

Error in `$<-.data.frame`(`*tmp*`, "_ids_", value = c(1L, 1L, 1L, 1L,  : 
  replacement has 400 rows, data has 80

This can be corrected with the following change:
In the file ceteris.paribus.R, line 146 is:
new_observation_ext$`_ids_` <- rep(1:nrow(new_observation), each = nrow(new_observation))

it should be:
new_observation_ext$`_ids_` <- rep(1:nrow(new_observation), each = length(col_yhat))

Toy example:

library("randomForest")
library("DALEX")

titanic <- na.omit(titanic)
# we predict embarked instead of survived for generating the bug
model_titanic_rf <- randomForest(embarked ~ gender + age + class + survived +
                                   fare + sibsp + parch,  data = titanic)
model_titanic_rf

explain_titanic_rf <- explain(model_titanic_rf,
                              data = titanic[,-4],
                              y = titanic$survived,
                              label = "Random Forest v7")

# select few passangers
selected_passangers <- select_sample(titanic, n = 20)
cp_rf <- ceteris_paribus(explain_titanic_rf, selected_passangers)
cp_rf
@pbiecek pbiecek added the bug 💣 label Jun 27, 2019
pbiecek added a commit that referenced this issue Jun 27, 2019
@pbiecek
Copy link
Member

@pbiecek pbiecek commented Jun 27, 2019

Thanks, fixed

@pbiecek pbiecek closed this Jun 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.