Skip to content

Commit

Permalink
#22 Add check for character variables in explainer dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
kromash committed Apr 14, 2019
1 parent 6665eea commit e7d00f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/modelDown.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ validateExplainers <- function(explainers){
if(class(explainer) != "explainer"){
stop("All explainers must be of class 'explainer' (generated by explain() from DALEX package)")
}

if(any(sapply(explainer$data, class) == "character")){
print("Found character variables:")
print(names(explainer$data)[sapply(explainer$data, class) == "character"])
stop("Character variables are not supported! Please remove them or convert to factors")
}
}

# Check if explainers have the same columns
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test_modelDown.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ test_that("Default arguments", {
})
})


test_that("Validation for character variable in explainer dataset", {
expect_error({
require("DALEX")

titanic_char <- titanic
titanic_char$country_character <- as.character(titanic$country)

titanic_glm_model <- glm(survived == "yes" ~ ., titanic_char, family = "binomial")

explainer_glm <-
explain(titanic_glm_model, data = titanic_char, y = titanic_char$survived)
modelDown::modelDown(explainer_glm)
})
})

0 comments on commit e7d00f3

Please sign in to comment.