Skip to content

Commit

Permalink
candidate fix for #75
Browse files Browse the repository at this point in the history
`variable_importance()` will be replaced by `ingredients::feature_importance()`
  • Loading branch information
pbiecek committed May 2, 2019
1 parent 27283a1 commit 1c840b6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ DALEX 0.4.0
----------------------------------------------------------------
* `ingredients` and `iBreakDown` are added to additional features ([#72](https://github.com/pbiecek/DALEX/issues/72)).
* `feature_response()` and `variable_response()` are marked as Deprecated. It is suggested to use `ingredients::partial_dependency()`, `ingredients::accumulated_dependency()` instead ([#74](https://github.com/pbiecek/DALEX/issues/74)).
* `variable_importance()` is marked as Deprecated. It is suggested to use `ingredients::feature_importance()` instead ([#75](https://github.com/pbiecek/DALEX/issues/75)).

DALEX 0.3.1
----------------------------------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions R/feature_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ feature_response <- function(x, ...)
feature_response.explainer <- function(x, feature, type = "pdp", which_class = NULL, ...) {
# Deprecated
if (type == "pdp") {
.Deprecated("ingredients::partial_dependency()", package = "ingredients", msg = "Please note that 'feature_response()' is now deprecated, it is better to use 'ingredients::partial_dependency()' instead.\nFind examples and detailed introduction at: https://pbiecek.github.io/PM_VEE/partialDependenceProfiles.html")
if (!exists("message_partial_dependency", envir = .DALEX.env)) {
.DALEX.env$message_partial_dependency = TRUE
.Deprecated("ingredients::partial_dependency()", package = "ingredients", msg = "Please note that 'feature_response()' is now deprecated, it is better to use 'ingredients::partial_dependency()' instead.\nFind examples and detailed introduction at: https://pbiecek.github.io/PM_VEE/partialDependenceProfiles.html")
}
} else {
.Deprecated("ingredients::accumulated_dependency()", package = "ingredients", msg = "Please note that 'feature_response()' is now deprecated, it is better to use 'ingredients::accumulated_dependency()' instead.\nFind examples and detailed introduction at: https://pbiecek.github.io/PM_VEE/accumulatedLocalProfiles.html")
if (!exists("message_accumulated_dependency", envir = .DALEX.env)) {
.DALEX.env$message_accumulated_dependency = TRUE
.Deprecated("ingredients::accumulated_dependency()", package = "ingredients", msg = "Please note that 'feature_response()' is now deprecated, it is better to use 'ingredients::accumulated_dependency()' instead.\nFind examples and detailed introduction at: https://pbiecek.github.io/PM_VEE/accumulatedLocalProfiles.html")
}
}

if (is.null(x$data)) stop("The feature_response() function requires explainers created with specified 'data' parameter.")
Expand Down
10 changes: 10 additions & 0 deletions R/variable_importance.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#' Feature Importance Calculated as Loss from Feature Dropout
#'
#' This function is set deprecated. It is suggested to use \code{\link[ingredients]{feature_importance}} instead.
#' Find information how to use these functions here: \url{https://pbiecek.github.io/PM_VEE/variableImportance.html}.
#'
#'
#' @param explainer a model to be explained, preprocessed by the 'explain' function
#' @param loss_function a function thet will be used to assess variable importance
#' @param ... other parameters
Expand Down Expand Up @@ -47,6 +51,12 @@ variable_importance <- function(explainer,
...,
type = "raw",
n_sample = 1000) {
# Deprecated, but print the message only once
if (!exists("message_variable_importance", envir = .DALEX.env)) {
.DALEX.env$message_variable_importance = TRUE
.Deprecated("ingredients::feature_importance()", package = "ingredients", msg = "Please note that 'variable_importance()' is now deprecated, it is better to use 'ingredients::feature_importance()' instead.\nFind examples and detailed introduction at: https://pbiecek.github.io/PM_VEE/variableImportance.html")
}

if (!("explainer" %in% class(explainer))) stop("The variable_importance() function requires an object created with explain() function.")
if (is.null(explainer$data)) stop("The variable_importance() function requires explainers created with specified 'data' parameter.")
if (is.null(explainer$y)) stop("The variable_importance() function requires explainers created with specified 'y' parameter.")
Expand Down
11 changes: 9 additions & 2 deletions R/variable_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@
variable_response <- function(explainer, variable, type = "pdp", trans = explainer$link, ...) {
# Deprecated
if (type == "pdp") {
.Deprecated("ingredients::partial_dependency()", package = "ingredients", msg = "Please note that 'variable_response()' is now deprecated, it is better to use 'ingredients::partial_dependency()' instead.\nFind examples and detailed introduction at: https://pbiecek.github.io/PM_VEE/partialDependenceProfiles.html")
if (!exists("message_partial_dependency", envir = .DALEX.env)) {
.DALEX.env$message_partial_dependency = TRUE
.Deprecated("ingredients::partial_dependency()", package = "ingredients", msg = "Please note that 'variable_response()' is now deprecated, it is better to use 'ingredients::partial_dependency()' instead.\nFind examples and detailed introduction at: https://pbiecek.github.io/PM_VEE/partialDependenceProfiles.html")
}
} else {
.Deprecated("ingredients::accumulated_dependency()", package = "ingredients", msg = "Please note that 'variable_response()' is now deprecated, it is better to use 'ingredients::accumulated_dependency()' instead.\nFind examples and detailed introduction at: https://pbiecek.github.io/PM_VEE/accumulatedLocalProfiles.html")
if (!exists("message_accumulated_dependency", envir = .DALEX.env)) {
.DALEX.env$message_accumulated_dependency = TRUE
.Deprecated("ingredients::accumulated_dependency()", package = "ingredients", msg = "Please note that 'variable_response()' is now deprecated, it is better to use 'ingredients::accumulated_dependency()' instead.\nFind examples and detailed introduction at: https://pbiecek.github.io/PM_VEE/accumulatedLocalProfiles.html")
}
}


if (!("explainer" %in% class(explainer))) stop("The variable_response() function requires an object created with explain() function.")
if (is.null(explainer$data)) stop("The variable_response() function requires explainers created with specified 'data' parameter.")
if (class(explainer$data[,variable]) == "factor" & type != "factor") {
Expand Down
2 changes: 2 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ quick.installed.packages <- function() {
paste(addons, collapse = ", "),".\nUse 'install_dependencies()' to get all suggested dependencies"))
)
}

.DALEX.env <- new.env()
3 changes: 2 additions & 1 deletion man/variable_importance.Rd

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

0 comments on commit 1c840b6

Please sign in to comment.