Skip to content

Commit

Permalink
More precised comment and fixed error message (#77)
Browse files Browse the repository at this point in the history
* More precised comment and fixed error message

* check for groups and type parameters

* docs and '& -> &&

* docs
  • Loading branch information
WojciechKretowicz authored and pbiecek committed Dec 5, 2019
1 parent 35f6d85 commit ccb18f9
Show file tree
Hide file tree
Showing 26 changed files with 318 additions and 115 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Depends: R (>= 3.0)
License: GPL
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
Imports:
DALEX,
ggplot2,
Expand Down
24 changes: 20 additions & 4 deletions R/aggregate_profiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param x a ceteris paribus explainer produced with function \code{ceteris_paribus()}
#' @param ... other explainers that shall be calculated together
#' @param variables if not \code{NULL} then aggregate only for selected \code{variables} will be calculated
#' @param type either \code{partial/conditional/accumulated} for parital dependence, conditional profiles of accumulated local effects
#' @param type either \code{partial/conditional/accumulated} for partial dependence, conditional profiles of accumulated local effects
#' @param groups a variable name that will be used for grouping.
#' By default \code{NULL} which means that no groups shall be calculated
#' @param variable_type a character. If \code{numerical} then only numerical variables will be calculated.
Expand Down Expand Up @@ -88,8 +88,9 @@ aggregate_profiles <- function(x, ...,
variables = NULL) {

check_variable_type(variable_type)
check_type(type)

# if there is more explainers, they should be merged into a single data frame
# if there is more ceteris paribuses, they should be merged into a single data frame
dfl <- c(list(x), list(...))
all_profiles <- do.call(rbind, dfl)
class(all_profiles) <- "data.frame"
Expand All @@ -99,8 +100,9 @@ aggregate_profiles <- function(x, ...,
# variables to use
all_variables <- na.omit(as.character(unique(all_profiles$`_vname_`)))
if (!is.null(variables)) {
all_variables <- intersect(all_variables, variables)
if (length(all_variables) == 0) stop(paste0("variables do not overlap with ", paste(all_variables, collapse = ", ")))
all_variables_intersect <- intersect(all_variables, variables)
if (length(all_variables_intersect) == 0) stop(paste0("parameter variables do not overlap with ", paste(all_variables, collapse = ", ")))
all_variables <- all_variables_intersect
}
# only numerical or only factors?
is_numeric <- sapply(all_profiles[, all_variables, drop = FALSE], is.numeric)
Expand Down Expand Up @@ -130,6 +132,10 @@ aggregate_profiles <- function(x, ...,
if (variable_type == "categorical") {
all_profiles$`_x_` <- as.character(apply(all_profiles, 1, function(x) x[x["_vname_"]]))
}

if (!is.null(groups) && ! groups %in% colnames(all_profiles)) {
stop("groups parameter is not a name of any column")
}

# standard partial profiles
# just average
Expand Down Expand Up @@ -338,3 +344,13 @@ check_variable_type <- function(variable_type) {
if (!(variable_type %in% c("numerical", "categorical")))
stop("variable_type needs to be 'numerical' or 'categorical'")
}

#'@noRd
#'@title Check if type is partial/conditional/accumulated
#'
#'@param type a character
#'
check_type <- function(type) {
if (!(type %in% c("partial", "conditional", "accumulated")))
stop("type needs to be 'partial', 'conditional' or 'accumulated'")
}
35 changes: 24 additions & 11 deletions man/accumulated_dependency.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions man/aggregate_profiles.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions man/calculate_variable_profile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions man/calculate_variable_split.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 22 additions & 7 deletions man/ceteris_paribus.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/ceteris_paribus_2d.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions man/cluster_profiles.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 24 additions & 11 deletions man/conditional_dependency.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 20 additions & 9 deletions man/describe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 28 additions & 11 deletions man/feature_importance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ccb18f9

Please sign in to comment.