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

add fix for #145 #147

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ingredients
Title: Effects and Importances of Model Ingredients
Version: 2.2.1
Version: 2.3.0
Authors@R: c(person("Przemyslaw", "Biecek", email = "przemyslaw.biecek@gmail.com",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8423-1823")),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
ingredients 2.3.0
--------------------------------------------------------------
* breaking change: `calculate_variable_splits()` now treats `integer` variables as `categorical`. This change is propagated to `ceteris_paribus()`, `partial_dependence()`, `accumulated_dependence()`, `conditional_dependence()`, `aggregate_profiles()`, `DALEX::predict_profile()`, `DALEX::model_profile()`
* fix an error in `ceteris_paribus` / `calculate_variable_splits` when `tidymodels` uses `integer` variables [#145](https://github.com/ModelOriented/ingredients/issues/145)

ingredients 2.2.1
--------------------------------------------------------------
* added `facet_scales` parameter to `plot.aggregated_profiles_explainer` (`'free_x'` by default) [#138](https://github.com/ModelOriented/ingredients/issues/138) and `plot.ceteris_paribus_explainer` (`'free_x'` or `'free_y'` by default, depending on plot type) [#136](https://github.com/ModelOriented/ingredients/issues/136)
Expand Down
13 changes: 10 additions & 3 deletions R/calculate_variable_profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ calculate_variable_split <- function(data, variables = colnames(data), grid_poin
calculate_variable_split.default <- function(data, variables = colnames(data), grid_points = 101, variable_splits_type = "quantiles", new_observation = NA) {
variable_splits <- lapply(variables, function(var) {
selected_column <- na.omit(data[,var])
# numeric?
if (is.numeric(selected_column)) {
# as per ?is.numeric : `is.numeric(x)` equals `is.double(x) || is.integer(x)`
if (is.double(selected_column)) {
probs <- seq(0, 1, length.out = grid_points)
if (variable_splits_type == "quantiles") {
# variable quantiles
Expand All @@ -93,7 +93,14 @@ calculate_variable_split.default <- function(data, variables = colnames(data), g
# fixing https://github.com/ModelOriented/ingredients/issues/124
if (!any(is.na(new_observation)))
selected_splits <- sort(unique(c(selected_splits, na.omit(new_observation[,var]))))
} else {
} else { # categorical OR integer fix for https://github.com/ModelOriented/ingredients/issues/145

if (length(unique(selected_column)) > 201) warning(
paste0("Variable: < ", var, " > has more than 201 unique values and all of them will be used as variable splits in calculating variable profiles.",
" Use the `variable_splits` parameter to mannualy change this behaviour.",
" If you believe this warning to be a false positive, raise issue at <https://github.com/ModelOriented/ingredients/issues>.")
)

# sort will change order of factors in a good way
if (any(is.na(new_observation))) {
selected_splits <- sort(unique(selected_column))
Expand Down