Skip to content

Commit

Permalink
potential fix for #134
Browse files Browse the repository at this point in the history
  • Loading branch information
hbaniecki committed Nov 9, 2020
1 parent 2ea9c4e commit 64f75a7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ingredients 2.0.1
--------------------------------------------------------------
* code and documentation maintenance [#130](https://github.com/ModelOriented/ingredients/issues/130)
* fixed an error when `N = NULL` in `partial_dependence()` etc. [#134](https://github.com/ModelOriented/ingredients/issues/134)

ingredients 2.0
--------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions R/accumulated_dependence.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
#' Will be passed to \code{\link{calculate_variable_split}}.
#' If \code{NULL} then all variables from the validation data will be used.
#' @param N number of observations used for calculation of partial dependence profiles.
#' By default, 500 observations will be chosen randomly.
#' By default, \code{500} observations will be chosen randomly.
#' @param ... other parameters
#' @param variable_splits named list of splits for variables, in most cases created with \code{\link{calculate_variable_split}}.
#' If \code{NULL} then it will be calculated based on validation data avaliable in the \code{explainer}.
#' @param grid_points number of points for profile. Will be passed to\code{\link{calculate_variable_split}}.
#' @param label name of the model. By default it's extracted from the \code{class} attribute of the model
#' @param variable_type a character. If "numerical" then only numerical variables will be calculated.
#' If "categorical" then only categorical variables will be calculated.
#' @param variable_type a character. If \code{"numerical"} then only numerical variables will be calculated.
#' If \code{"categorical"} then only categorical variables will be calculated.
#'
#' @references ALEPlot: Accumulated Local Effects (ALE) Plots and Partial Dependence (PD) Plots \url{https://cran.r-project.org/package=ALEPlot},
#' Explanatory Model Analysis. Explore, Explain, and Examine Predictive Models. \url{https://pbiecek.github.io/ema/}
Expand Down Expand Up @@ -106,7 +106,7 @@ accumulated_dependence.default <- function(x,
grid_points = 101,
...,
variable_type = "numerical") {
if (N < nrow(data)) {
if (!is.null(N) && N < nrow(data)) {
# sample N points
ndata <- data[sample(1:nrow(data), N),]
} else {
Expand Down
8 changes: 4 additions & 4 deletions R/conditional_dependence.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#' @param predict_function predict function, will be extracted from \code{x} if it's an explainer
#' @param variables names of variables for which profiles shall be calculated.
#' Will be passed to \code{\link{calculate_variable_split}}. If \code{NULL} then all variables from the validation data will be used.
#' @param N number of observations used for calculation of partial dependence profiles. By default 500.
#' @param N number of observations used for calculation of partial dependence profiles. By default \code{500}.
#' @param ... other parameters
#' @param variable_splits named list of splits for variables, in most cases created with \code{\link{calculate_variable_split}}.
#' If \code{NULL} then it will be calculated based on validation data avaliable in the \code{explainer}.
#' @param grid_points number of points for profile. Will be passed to \code{\link{calculate_variable_split}}.
#' @param label name of the model. By default it's extracted from the \code{class} attribute of the model
#' @param variable_type a character. If \code{numerical} then only numerical variables will be calculated.
#' If \code{categorical} then only categorical variables will be calculated.
#' @param variable_type a character. If \code{"numerical"} then only numerical variables will be calculated.
#' If \code{"categorical"} then only categorical variables will be calculated.
#'
#' @references Explanatory Model Analysis. Explore, Explain, and Examine Predictive Models. \url{https://pbiecek.github.io/ema/}
#'
Expand Down Expand Up @@ -103,7 +103,7 @@ conditional_dependence.default <- function(x,
...,
variable_type = "numerical") {

if (N < nrow(data)) {
if (!is.null(N) && N < nrow(data)) {
# sample N points
ndata <- data[sample(1:nrow(data), N),]
} else {
Expand Down
8 changes: 4 additions & 4 deletions R/partial_dependence.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#' @param variables names of variables for which profiles shall be calculated.
#' Will be passed to \code{\link{calculate_variable_split}}.
#' If \code{NULL} then all variables from the validation data will be used.
#' @param N number of observations used for calculation of partial dependence profiles. By default 500.
#' @param N number of observations used for calculation of partial dependence profiles. By default \code{500}.
#' @param ... other parameters
#' @param variable_splits named list of splits for variables, in most cases created with \code{\link{calculate_variable_split}}.
#' If \code{NULL} then it will be calculated based on validation data avaliable in the \code{explainer}.
#' @param grid_points number of points for profile. Will be passed to \code{\link{calculate_variable_split}}.
#' @param label name of the model. By default it's extracted from the \code{class} attribute of the model
#' @param variable_type a character. If \code{numerical} then only numerical variables will be calculated.
#' If \code{categorical} then only categorical variables will be calculated.
#' @param variable_type a character. If \code{"numerical"} then only numerical variables will be calculated.
#' If \code{"categorical"} then only categorical variables will be calculated.
#'
#' @references Explanatory Model Analysis. Explore, Explain, and Examine Predictive Models. \url{https://pbiecek.github.io/ema/}
#'
Expand Down Expand Up @@ -104,7 +104,7 @@ partial_dependence.default <- function(x,
N = 500,
...,
variable_type = "numerical") {
if (N < nrow(data)) {
if (!is.null(N) && N < nrow(data)) {
# sample N points
ndata <- data[sample(1:nrow(data), N),]
} else {
Expand Down
6 changes: 3 additions & 3 deletions man/accumulated_dependence.Rd

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

6 changes: 3 additions & 3 deletions man/conditional_dependence.Rd

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

6 changes: 3 additions & 3 deletions man/partial_dependence.Rd

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

0 comments on commit 64f75a7

Please sign in to comment.