diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 0528262..a3ac618 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,4 +1,4 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: config: - - {os: macOS-latest, r: 'release'} + - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} @@ -29,30 +29,21 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true - - uses: r-lib/actions/setup-r-dependencies@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: rcmdcheck + extra-packages: any::rcmdcheck + needs: check - - uses: r-lib/actions/check-r-package@v1 - - - name: Show testthat output - if: always() - run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true - shell: bash - - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main + - uses: r-lib/actions/check-r-package@v2 with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check + upload-snapshots: true diff --git a/DESCRIPTION b/DESCRIPTION index 605e1c0..95c725b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: randomForestExplainer Title: Explaining and Visualizing Random Forests in Terms of Variable Importance -Version: 0.10.1 +Version: 0.10.2 Authors@R: c( person("Aleksandra", "Paluszynska", email = "ola.paluszynska@gmail.com", role = c("aut")), person("Przemyslaw", "Biecek", email = "przemyslaw.biecek@gmail.com", role = c("aut","ths")), @@ -10,22 +10,24 @@ Description: A set of tools to help explain which variables are most important i Depends: R (>= 3.0) License: GPL Encoding: UTF-8 -LazyData: true Imports: data.table (>= 1.10.4), dplyr (>= 0.7.1), DT (>= 0.2), GGally (>= 1.3.0), - ggplot2 (>= 2.2.1), + ggplot2 (>= 3.4.0), ggrepel (>= 0.6.5), randomForest (>= 4.6.12), ranger(>= 0.9.0), - reshape2 (>= 1.4.2), - rmarkdown (>= 1.5) + rlang, + rmarkdown (>= 1.5), + tidyr Suggests: knitr, MASS (>= 7.3.47), testthat VignetteBuilder: knitr -RoxygenNote: 7.1.0 +RoxygenNote: 7.3.0 URL: https://github.com/ModelOriented/randomForestExplainer, https://modeloriented.github.io/randomForestExplainer/ +Config/testthat/edition: 3 +Config/Needs/website: ModelOriented/DrWhyTemplate diff --git a/NAMESPACE b/NAMESPACE index 680841b..bb42932 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,6 +26,7 @@ import(ggplot2) import(ggrepel) importFrom(data.table,frankv) importFrom(data.table,rbindlist) +importFrom(rlang,.data) importFrom(stats,as.formula) importFrom(stats,predict) importFrom(stats,terms) diff --git a/NEWS.md b/NEWS.md index 7b9992f..e99f98e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,22 @@ +# randomForestExplainer 0.10.2 + +* Remove dependency on reshape2 in favour of tidyr (@olivroy, #33) + +* Silence deprecation warnings from ggplot2 and dplyr (@olivroy, #29) + +* Use testthat 3rd edition. (@olivroy, #33) + +# randomForestExplainer 0.10.1 + +* Small tweaks to `explain_forest()`. + # randomForestExplainer 0.10.0 + ## New features * Added support for ranger forests. * Added support for unsupervised randomForest. * Added tests for most functions. ## Bug fixes -* Fixed bug for explain_forest not finding templates. -* Added more intuitive error message for explain_forest when local importance is absent. +* Fixed bug for `explain_forest()` not finding templates. +* Added more intuitive error message for `explain_forest()` when local `importance` is absent. diff --git a/R/measure_importance.R b/R/measure_importance.R index b3a16e9..5773916 100644 --- a/R/measure_importance.R +++ b/R/measure_importance.R @@ -10,8 +10,7 @@ measure_min_depth <- function(min_depth_frame, mean_sample){ # randomForest measure_no_of_nodes <- function(forest_table){ `split var` <- NULL - frame <- dplyr::group_by(forest_table, `split var`) %>% dplyr::summarize(n()) - colnames(frame) <- c("variable", "no_of_nodes") + frame <- dplyr::group_by(forest_table, variable = `split var`) %>% dplyr::summarize(no_of_nodes = dplyr::n()) frame <- as.data.frame(frame[!is.na(frame$variable),]) frame$variable <- as.character(frame$variable) return(frame) @@ -21,8 +20,7 @@ measure_no_of_nodes <- function(forest_table){ # randomForest measure_no_of_nodes_ranger <- function(forest_table){ splitvarName <- NULL - frame <- dplyr::group_by(forest_table, splitvarName) %>% dplyr::summarize(n()) - colnames(frame) <- c("variable", "no_of_nodes") + frame <- dplyr::group_by(forest_table, variable = splitvarName) %>% dplyr::summarize(no_of_nodes = n()) frame <- as.data.frame(frame[!is.na(frame$variable),]) frame$variable <- as.character(frame$variable) return(frame) @@ -75,8 +73,7 @@ measure_vimp_ranger <- function(forest){ measure_no_of_trees <- function(min_depth_frame){ variable <- NULL frame <- dplyr::group_by(min_depth_frame, variable) %>% - dplyr::summarize(count = n()) %>% as.data.frame() - colnames(frame)[2] <- "no_of_trees" + dplyr::summarize(no_of_trees = n()) %>% as.data.frame() frame$variable <- as.character(frame$variable) return(frame) } @@ -85,8 +82,7 @@ measure_no_of_trees <- function(min_depth_frame){ measure_times_a_root <- function(min_depth_frame){ variable <- NULL frame <- min_depth_frame[min_depth_frame$minimal_depth == 0, ] %>% - dplyr::group_by(variable) %>% dplyr::summarize(count = n()) %>% as.data.frame() - colnames(frame)[2] <- "times_a_root" + dplyr::group_by(variable) %>% dplyr::summarize(times_a_root = n()) %>% as.data.frame() frame$variable <- as.character(frame$variable) return(frame) } @@ -329,13 +325,13 @@ plot_multi_way_importance <- function(importance_frame, x_measure = "mean_min_de if(size_measure == "p_value"){ data$p_value <- cut(data$p_value, breaks = c(-Inf, 0.01, 0.05, 0.1, Inf), labels = c("<0.01", "[0.01, 0.05)", "[0.05, 0.1)", ">=0.1"), right = FALSE) - plot <- ggplot(data, aes_string(x = x_measure, y = y_measure)) + - geom_point(aes_string(color = size_measure), size = 3) + + plot <- ggplot(data, aes(x = .data[[x_measure]], y = .data[[y_measure]])) + + geom_point(aes(color = .data[[size_measure]]), size = 3) + geom_point(data = data_for_labels, color = "black", stroke = 2, aes(alpha = "top"), size = 3, shape = 21) + geom_label_repel(data = data_for_labels, aes(label = variable), show.legend = FALSE) + theme_bw() + scale_alpha_discrete(name = "variable", range = c(1, 1)) } else { - plot <- ggplot(data, aes_string(x = x_measure, y = y_measure, size = size_measure)) + + plot <- ggplot(data, aes(x = .data[[x_measure]], y = .data[[y_measure]], size = .data[[size_measure]])) + geom_point(aes(colour = "black")) + geom_point(data = data_for_labels, aes(colour = "blue")) + geom_label_repel(data = data_for_labels, aes(label = variable, size = NULL), show.legend = FALSE) + scale_colour_manual(name = "variable", values = c("black", "blue"), labels = c("non-top", "top")) + @@ -345,7 +341,7 @@ plot_multi_way_importance <- function(importance_frame, x_measure = "mean_min_de } } } else { - plot <- ggplot(data, aes_string(x = x_measure, y = y_measure)) + + plot <- ggplot(data, aes(x = .data[[x_measure]], y = .data[[y_measure]])) + geom_point(aes(colour = "black")) + geom_point(data = data_for_labels, aes(colour = "blue")) + geom_label_repel(data = data_for_labels, aes(label = variable, size = NULL), show.legend = FALSE) + scale_colour_manual(name = "variable", values = c("black", "blue"), labels = c("non-top", "top")) + diff --git a/R/min_depth_distribution.R b/R/min_depth_distribution.R index fd54f1c..5beb787 100644 --- a/R/min_depth_distribution.R +++ b/R/min_depth_distribution.R @@ -175,7 +175,7 @@ plot_min_depth_distribution <- function(min_depth_frame, k = 10, min_no_of_trees plot <- ggplot(data, aes(x = variable, y = count)) + geom_col(position = position_stack(reverse = TRUE), aes(fill = as.factor(minimal_depth))) + coord_flip() + scale_x_discrete(limits = rev(levels(data$variable))) + - geom_errorbar(aes(ymin = mean_minimal_depth_label, ymax = mean_minimal_depth_label), size = 1.5) + + geom_errorbar(aes(ymin = mean_minimal_depth_label, ymax = mean_minimal_depth_label), linewidth = 1.5) + xlab("Variable") + ylab("Number of trees") + guides(fill = guide_legend(title = "Minimal depth")) + theme_bw() + geom_label(data = data_for_labels, aes(y = mean_minimal_depth_label, label = mean_minimal_depth)) diff --git a/R/min_depth_interactions.R b/R/min_depth_interactions.R index 6627ac0..8f047c2 100644 --- a/R/min_depth_interactions.R +++ b/R/min_depth_interactions.R @@ -63,17 +63,22 @@ min_depth_interactions_values <- function(forest, vars){ mutate_if(is.factor, as.character) %>% calculate_tree_depth() %>% cbind(., tree = i, number = 1:nrow(.))) %>% data.table::rbindlist() %>% as.data.frame() - interactions_frame[vars] <- as.numeric(NA) + interactions_frame[vars] <- NA_real_ interactions_frame <- data.table::as.data.table(interactions_frame)[, conditional_depth(as.data.frame(.SD), vars), by = tree] %>% as.data.frame() mean_tree_depth <- dplyr::group_by(interactions_frame[, c("tree", vars)], tree) %>% - dplyr::summarize_at(vars, funs(max(., na.rm = TRUE))) %>% as.data.frame() - mean_tree_depth[mean_tree_depth == -Inf] <- NA + dplyr::summarise( + dplyr::across({{ vars }}, .fns = max_na) + ) %>% + as.data.frame() mean_tree_depth <- colMeans(mean_tree_depth[, vars, drop = FALSE], na.rm = TRUE) + min_depth_interactions_frame <- interactions_frame %>% dplyr::group_by(tree, `split var`) %>% - dplyr::summarize_at(vars, funs(min(., na.rm = TRUE))) %>% as.data.frame() - min_depth_interactions_frame[min_depth_interactions_frame == Inf] <- NA + dplyr::summarise( + dplyr::across({{ vars }}, .fns = min_na) + ) %>% + as.data.frame() min_depth_interactions_frame <- min_depth_interactions_frame[!is.na(min_depth_interactions_frame$`split var`), ] colnames(min_depth_interactions_frame)[2] <- "variable" min_depth_interactions_frame[, -c(1:2)] <- min_depth_interactions_frame[, -c(1:2)] - 1 @@ -88,19 +93,22 @@ min_depth_interactions_values_ranger <- function(forest, vars){ lapply(1:forest$num.trees, function(i) ranger::treeInfo(forest, tree = i) %>% calculate_tree_depth_ranger() %>% cbind(., tree = i, number = 1:nrow(.))) %>% data.table::rbindlist() %>% as.data.frame() - interactions_frame[vars] <- as.numeric(NA) + interactions_frame[vars] <- NA_real_ interactions_frame <- data.table::as.data.table(interactions_frame)[, conditional_depth_ranger(as.data.frame(.SD), vars), by = tree] %>% as.data.frame() mean_tree_depth <- dplyr::group_by(interactions_frame[, c("tree", vars)], tree) %>% - dplyr::summarize_at(vars, funs(max(., na.rm = TRUE))) %>% as.data.frame() - mean_tree_depth[mean_tree_depth == -Inf] <- NA + dplyr::summarise( + dplyr::across({{ vars }}, .fns = max_na) + ) %>% + as.data.frame() mean_tree_depth <- colMeans(mean_tree_depth[, vars, drop = FALSE], na.rm = TRUE) min_depth_interactions_frame <- - interactions_frame %>% dplyr::group_by(tree, splitvarName) %>% - dplyr::summarize_at(vars, funs(min(., na.rm = TRUE))) %>% as.data.frame() - min_depth_interactions_frame[min_depth_interactions_frame == Inf] <- NA - min_depth_interactions_frame <- min_depth_interactions_frame[!is.na(min_depth_interactions_frame$splitvarName), ] - colnames(min_depth_interactions_frame)[2] <- "variable" + interactions_frame %>% dplyr::group_by(tree, variable = splitvarName) %>% + dplyr::summarise( + dplyr::across(.cols = {{ vars }}, .fns = min_na) + ) %>% + as.data.frame() + min_depth_interactions_frame <- min_depth_interactions_frame[!is.na(min_depth_interactions_frame$variable), ] min_depth_interactions_frame[, -c(1:2)] <- min_depth_interactions_frame[, -c(1:2)] - 1 return(list(min_depth_interactions_frame, mean_tree_depth)) } @@ -137,11 +145,17 @@ min_depth_interactions.randomForest <- function(forest, vars = important_variabl min_depth_interactions_frame <- min_depth_interactions_frame[[1]] interactions_frame <- min_depth_interactions_frame %>% dplyr::group_by(variable) %>% - dplyr::summarize_at(vars, funs(mean(., na.rm = TRUE))) %>% as.data.frame() + dplyr::summarise( + dplyr::across({{ vars }}, function(x) mean(x, na.rm = TRUE)) + ) %>% + as.data.frame() interactions_frame[is.na(as.matrix(interactions_frame))] <- NA occurrences <- min_depth_interactions_frame %>% dplyr::group_by(variable) %>% - dplyr::summarize_at(vars, funs(sum(!is.na(.)))) %>% as.data.frame() + dplyr::summarise( + dplyr::across({{ vars }}, function(x) sum(!is.na(x))) + ) %>% + as.data.frame() if(mean_sample == "all_trees"){ non_occurrences <- occurrences non_occurrences[, -1] <- forest$ntree - occurrences[, -1] @@ -157,19 +171,26 @@ min_depth_interactions.randomForest <- function(forest, vars = important_variabl interactions_frame[, -1] <- (interactions_frame[, -1] * occurrences[, -1] + as.matrix(non_occurrences[, -1]) %*% diag(mean_tree_depth, nrow = length(mean_tree_depth)))/(forest$ntree - minimum_non_occurrences) } - interactions_frame <- reshape2::melt(interactions_frame, id.vars = "variable") - colnames(interactions_frame)[2:3] <- c("root_variable", "mean_min_depth") - occurrences <- reshape2::melt(occurrences, id.vars = "variable") - colnames(occurrences)[2:3] <- c("root_variable", "occurrences") + interactions_frame <- tidyr::pivot_longer( + interactions_frame, + cols = -"variable", + names_to = "root_variable", + values_to = "mean_min_depth" + ) + occurrences <- tidyr::pivot_longer( + occurrences, + cols = -"variable", + names_to = "root_variable", + values_to = "occurrences" + ) interactions_frame <- merge(interactions_frame, occurrences) interactions_frame$interaction <- paste(interactions_frame$root_variable, interactions_frame$variable, sep = ":") forest_table <- lapply(1:forest$ntree, function(i) randomForest::getTree(forest, k = i, labelVar = T) %>% mutate_if(is.factor, as.character) %>% calculate_tree_depth() %>% cbind(tree = i)) %>% rbindlist() - min_depth_frame <- dplyr::group_by(forest_table, tree, `split var`) %>% - dplyr::summarize(min(depth)) - colnames(min_depth_frame) <- c("tree", "variable", "minimal_depth") + min_depth_frame <- dplyr::group_by(forest_table, tree, variable = `split var`) %>% + dplyr::summarize(minimal_depth = min(depth)) min_depth_frame <- as.data.frame(min_depth_frame[!is.na(min_depth_frame$variable),]) importance_frame <- get_min_depth_means(min_depth_frame, min_depth_count(min_depth_frame), uncond_mean_sample) colnames(importance_frame)[2] <- "uncond_mean_min_depth" @@ -187,11 +208,17 @@ min_depth_interactions.ranger <- function(forest, vars = important_variables(mea min_depth_interactions_frame <- min_depth_interactions_frame[[1]] interactions_frame <- min_depth_interactions_frame %>% dplyr::group_by(variable) %>% - dplyr::summarize_at(vars, funs(mean(., na.rm = TRUE))) %>% as.data.frame() + dplyr::summarise( + dplyr::across({{ vars }}, function(x) mean(x, na.rm = TRUE)) + ) %>% + as.data.frame() interactions_frame[is.na(as.matrix(interactions_frame))] <- NA occurrences <- min_depth_interactions_frame %>% dplyr::group_by(variable) %>% - dplyr::summarize_at(vars, funs(sum(!is.na(.)))) %>% as.data.frame() + dplyr::summarise( + dplyr::across({{ vars }}, function(x) sum(!is.na(x), na.rm = TRUE)) + ) %>% + as.data.frame() if(mean_sample == "all_trees"){ non_occurrences <- occurrences non_occurrences[, -1] <- forest$num.trees - occurrences[, -1] @@ -207,18 +234,15 @@ min_depth_interactions.ranger <- function(forest, vars = important_variables(mea interactions_frame[, -1] <- (interactions_frame[, -1] * occurrences[, -1] + as.matrix(non_occurrences[, -1]) %*% diag(mean_tree_depth, nrow = length(mean_tree_depth)))/(forest$num.trees - minimum_non_occurrences) } - interactions_frame <- reshape2::melt(interactions_frame, id.vars = "variable") - colnames(interactions_frame)[2:3] <- c("root_variable", "mean_min_depth") - occurrences <- reshape2::melt(occurrences, id.vars = "variable") - colnames(occurrences)[2:3] <- c("root_variable", "occurrences") + interactions_frame <- tidyr::pivot_longer(interactions_frame, cols = -"variable", names_to = "root_variable", values_to = "mean_min_depth") + occurrences <- tidyr::pivot_longer(occurrences, cols = -"variable", names_to = "root_variable", values_to = "occurrences") interactions_frame <- merge(interactions_frame, occurrences) interactions_frame$interaction <- paste(interactions_frame$root_variable, interactions_frame$variable, sep = ":") forest_table <- lapply(1:forest$num.trees, function(i) ranger::treeInfo(forest, tree = i) %>% calculate_tree_depth_ranger() %>% cbind(tree = i)) %>% rbindlist() - min_depth_frame <- dplyr::group_by(forest_table, tree, splitvarName) %>% - dplyr::summarize(min(depth)) - colnames(min_depth_frame) <- c("tree", "variable", "minimal_depth") + min_depth_frame <- dplyr::group_by(forest_table, tree, variable = splitvarName) %>% + dplyr::summarize(minimal_depth = min(depth)) min_depth_frame <- as.data.frame(min_depth_frame[!is.na(min_depth_frame$variable),]) importance_frame <- get_min_depth_means(min_depth_frame, min_depth_count(min_depth_frame), uncond_mean_sample) colnames(importance_frame)[2] <- "uncond_mean_min_depth" @@ -251,14 +275,14 @@ plot_min_depth_interactions <- function(interactions_frame, k = 30, interactions_frame[ order(interactions_frame$occurrences, decreasing = TRUE), "interaction"]) minimum <- min(interactions_frame$mean_min_depth, na.rm = TRUE) - if(is.null(k)) k <- length(levels(interactions_frame$interaction)) + if(is.null(k)) k <- nlevels(interactions_frame$interaction) plot <- ggplot(interactions_frame[interactions_frame$interaction %in% levels(interactions_frame$interaction)[1:k] & !is.na(interactions_frame$mean_min_depth), ], aes(x = interaction, y = mean_min_depth, fill = occurrences)) + geom_bar(stat = "identity") + geom_pointrange(aes(ymin = pmin(mean_min_depth, uncond_mean_min_depth), y = uncond_mean_min_depth, ymax = pmax(mean_min_depth, uncond_mean_min_depth), shape = "unconditional"), fatten = 2, size = 1) + - geom_hline(aes(yintercept = minimum, linetype = "minimum"), color = "red", size = 1.5) + + geom_hline(aes(yintercept = minimum, linetype = "minimum"), color = "red", linewidth = 1.5) + scale_linetype_manual(name = NULL, values = 1) + theme_bw() + scale_shape_manual(name = NULL, values = 19) + theme(axis.text.x = element_text(angle = 45, hjust = 1)) @@ -324,7 +348,7 @@ plot_predict_interaction.randomForest <- function(forest, data, variable1, varia } if(forest$type == "regression"){ newdata$prediction <- predict(forest, newdata, type = "response") - plot <- ggplot(newdata, aes_string(x = variable1, y = variable2, fill = "prediction")) + + plot <- ggplot(newdata, aes(x = .data[[variable1]], y = .data[[variable2]], fill = prediction)) + geom_raster() + theme_bw() + scale_fill_gradient2(midpoint = min(newdata$prediction) + 0.5 * (max(newdata$prediction) - min(newdata$prediction)), low = "blue", high = "red") @@ -335,9 +359,9 @@ plot_predict_interaction.randomForest <- function(forest, data, variable1, varia } else { newdata[, paste0("probability_", forest$classes)] <- predict(forest, newdata, type = "prob") } - newdata <- reshape2::melt(newdata, id.vars = id_vars) + newdata <- tidyr::pivot_longer(newdata, cols = !dplyr::all_of(id_vars), names_to = "variable") newdata$prediction <- newdata$value - plot <- ggplot(newdata, aes_string(x = variable1, y = variable2, fill = "prediction")) + + plot <- ggplot(newdata, aes(x = .data[[variable1]], y = .data[[variable2]], fill = prediction)) + geom_raster() + theme_bw() + facet_wrap(~ variable) + scale_fill_gradient2(midpoint = min(newdata$prediction) + 0.5 * (max(newdata$prediction) - min(newdata$prediction)), low = "blue", high = "red") @@ -352,6 +376,7 @@ plot_predict_interaction.randomForest <- function(forest, data, variable1, varia #' @importFrom stats predict #' @importFrom stats terms #' @importFrom stats as.formula +#' @importFrom rlang .data #' @export plot_predict_interaction.ranger <- function(forest, data, variable1, variable2, grid = 100, main = paste0("Prediction of the forest for different values of ", @@ -372,7 +397,7 @@ plot_predict_interaction.ranger <- function(forest, data, variable1, variable2, } if(forest$treetype == "Regression"){ newdata$prediction <- predict(forest, newdata, type = "response")$predictions - plot <- ggplot(newdata, aes_string(x = variable1, y = variable2, fill = "prediction")) + + plot <- ggplot(newdata, aes(x = .data[[variable1]], y = .data[[variable2]], fill = prediction)) + geom_raster() + theme_bw() + scale_fill_gradient2(midpoint = min(newdata$prediction) + 0.5 * (max(newdata$prediction) - min(newdata$prediction)), low = "blue", high = "red") @@ -384,9 +409,9 @@ plot_predict_interaction.ranger <- function(forest, data, variable1, variable2, } else { newdata[, paste0("probability_", colnames(pred))] <- pred } - newdata <- reshape2::melt(newdata, id.vars = id_vars) + newdata <- tidyr::pivot_longer(newdata, cols = !dplyr::all_of(id_vars), names_to = "variable") newdata$prediction <- newdata$value - plot <- ggplot(newdata, aes_string(x = variable1, y = variable2, fill = "prediction")) + + plot <- ggplot(newdata, aes(x = .data[[variable1]], y = .data[[variable2]], fill = prediction)) + geom_raster() + theme_bw() + facet_wrap(~ variable) + scale_fill_gradient2(midpoint = min(newdata$prediction) + 0.5 * (max(newdata$prediction) - min(newdata$prediction)), low = "blue", high = "red") @@ -403,7 +428,7 @@ plot_predict_interaction.ranger <- function(forest, data, variable1, variable2, time <- new_time } newdata$prediction <- pred$survival[, pred$unique.death.times == time, drop = TRUE] - plot <- ggplot(newdata, aes_string(x = variable1, y = variable2, fill = "prediction")) + + plot <- ggplot(newdata, aes(x = .data[[variable1]], y = .data[[variable2]], fill = prediction)) + geom_raster() + theme_bw() + scale_fill_gradient2(midpoint = min(newdata$prediction) + 0.5 * (max(newdata$prediction) - min(newdata$prediction)), low = "blue", high = "red") diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 0000000..14099c3 --- /dev/null +++ b/R/utils.R @@ -0,0 +1,25 @@ +# Helpers to avoid warnings in computations +# Are all values NA? +all_na <- function(x) { + if (!anyNA(x)) { + return(FALSE) + } + all(is.na(x)) +} +# Min but returns NA if only has NA +min_na <- function(x) { + if (all_na(x)) { + return(NA) + } + min(x, na.rm = TRUE) +} +# max but returns NA if only has NA +max_na <- function(x) { + if (all_na(x)) { + return(NA) + } + max(x, na.rm = TRUE) +} + +utils::globalVariables(c("prediction", "variable")) + diff --git a/README.md b/README.md index fcbd04a..12ae211 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,15 @@ # randomForestExplainer -[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/randomForestExplainer)](https://cran.r-project.org/package=randomForestExplainer) -[![R-CMD-check](https://github.com/ModelOriented/randomForestExplainer/workflows/R-CMD-check/badge.svg)](https://github.com/ModelOriented/randomForestExplainer/actions) -[![codecov](https://codecov.io/gh/ModelOriented/randomForestExplainer/branch/master/graph/badge.svg)](https://codecov.io/gh/ModelOriented/randomForestExplainer) + + + +[![CRAN status](https://www.r-pkg.org/badges/version/randomForestExplainer)](https://cran.r-project.org/package=randomForestExplainer) +[![R-CMD-check](https://github.com/ModelOriented/randomForestExplainer/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ModelOriented/randomForestExplainer/actions/workflows/R-CMD-check.yaml) +[![codecov](https://codecov.io/gh/ModelOriented/randomForestExplainer/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ModelOriented/randomForestExplainer?branch=master) [![DOI](https://zenodo.org/badge/97007621.svg)](https://zenodo.org/badge/latestdoi/97007621) + -A set of tools to understand what is happening inside a Random Forest. A detailed discussion of the package and importance measures it implements can be found here: [Master thesis on randomForestExplainer](https://cdn.staticaly.com/gh/geneticsMiNIng/BlackBoxOpener/master/randomForestExplainer_Master_thesis.pdf). +A set of tools to understand what is happening inside a Random Forest. A detailed discussion of the package and importance measures it implements can be found here: [Master thesis on randomForestExplainer](https://github.com/geneticsMiNIng/BlackBoxOpener/blob/master/randomForestExplainer_Master_thesis.pdf). ## Installation diff --git a/docs/404.html b/docs/404.html index d20490d..554e992 100644 --- a/docs/404.html +++ b/docs/404.html @@ -1,88 +1,40 @@ - - - - + + + + - Page not found (404) • randomForestExplainer - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - + +
-
- + +
+ + + - - -
+
+
-
- - diff --git a/docs/articles/index.html b/docs/articles/index.html index ee7454e..b36d455 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -1,88 +1,16 @@ - - - - - - - -Articles • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Articles • randomForestExplainer - - - - - - - - +
-
- -
- -
+
-
- - - + diff --git a/docs/articles/randomForestExplainer.html b/docs/articles/randomForestExplainer.html index befcb57..0ab72fd 100644 --- a/docs/articles/randomForestExplainer.html +++ b/docs/articles/randomForestExplainer.html @@ -48,20 +48,14 @@ -
-

-Various variable importance measures

-

To further explore variable importance measures we pass our forest to measure_importance function and get the following data frame (we save and load it from memory to save time):

+
+

Various variable importance measures +

+

To further explore variable importance measures we pass our forest to +measure_importance function and get the following data +frame (we save and load it from memory to save time):

-# importance_frame <- measure_importance(forest)
-# save(importance_frame, file = "importance_frame.rda")
-load("importance_frame.rda")
-importance_frame
-
##    variable mean_min_depth no_of_nodes mse_increase node_purity_increase
-## 1       age       3.308000        8936    3.7695582            1144.6959
-## 2     black       3.512000        7855    1.6677224             762.5438
-## 3      chas       6.591152         761    0.4931158             193.7997
-## 4      crim       2.386000        9434    8.8550476            2556.8119
-## 5       dis       2.600000        9210    7.5408462            2461.5665
-## 6     indus       3.166000        4182    7.5565917            3083.5072
-## 7     lstat       1.288000       11443   62.8221475           12401.4000
-## 8       nox       2.578000        6187   10.3991589            2625.6542
-## 9   ptratio       2.868000        4572    6.5315832            2269.6530
-## 10      rad       5.115968        2631    1.2258054             324.9312
-## 11       rm       1.346000       11394   34.8226290           12848.2579
-## 12      tax       3.556000        4402    3.5985825            1090.7962
-## 13       zn       6.087424        1529    0.6720070             300.3424
-##    no_of_trees times_a_root       p_value
-## 1          500            2 8.381103e-225
-## 2          500            1  5.822067e-81
-## 3          411            0  1.000000e+00
-## 4          500           23 6.498487e-313
-## 5          500            1 1.188152e-271
-## 6          500           96  1.000000e+00
-## 7          500          135  0.000000e+00
-## 8          500           36  9.833401e-01
-## 9          500           46  1.000000e+00
-## 10         499            4  1.000000e+00
-## 11         500          139  0.000000e+00
-## 12         500           11  1.000000e+00
-## 13         482            6  1.000000e+00
-

It contains 13 rows, each corresponding to a predictor, and 8 columns of which one stores the variable names and the rest store the variable importance measures of a variable \(X_j\):

+# importance_frame <- measure_importance(forest) +# save(importance_frame, file = "importance_frame.rda") +load("importance_frame.rda") +importance_frame
+
##    variable mean_min_depth no_of_nodes mse_increase node_purity_increase
+## 1       age       3.308000        8936    3.7695582            1144.6959
+## 2     black       3.512000        7855    1.6677224             762.5438
+## 3      chas       6.591152         761    0.4931158             193.7997
+## 4      crim       2.386000        9434    8.8550476            2556.8119
+## 5       dis       2.600000        9210    7.5408462            2461.5665
+## 6     indus       3.166000        4182    7.5565917            3083.5072
+## 7     lstat       1.288000       11443   62.8221475           12401.4000
+## 8       nox       2.578000        6187   10.3991589            2625.6542
+## 9   ptratio       2.868000        4572    6.5315832            2269.6530
+## 10      rad       5.115968        2631    1.2258054             324.9312
+## 11       rm       1.346000       11394   34.8226290           12848.2579
+## 12      tax       3.556000        4402    3.5985825            1090.7962
+## 13       zn       6.087424        1529    0.6720070             300.3424
+##    no_of_trees times_a_root       p_value
+## 1          500            2 8.381103e-225
+## 2          500            1  5.822067e-81
+## 3          411            0  1.000000e+00
+## 4          500           23 6.498487e-313
+## 5          500            1 1.188152e-271
+## 6          500           96  1.000000e+00
+## 7          500          135  0.000000e+00
+## 8          500           36  9.833401e-01
+## 9          500           46  1.000000e+00
+## 10         499            4  1.000000e+00
+## 11         500          139  0.000000e+00
+## 12         500           11  1.000000e+00
+## 13         482            6  1.000000e+00
+

It contains 13 rows, each corresponding to a predictor, and 8 columns +of which one stores the variable names and the rest store the variable +importance measures of a variable \(X_j\):

    -
  1. accuracy_decrease (classification) – mean decrease of prediction accuracy after \(X_j\) is permuted,

  2. -
  3. gini_decrease (classification) – mean decrease in the Gini index of node impurity (i.e. increase of node purity) by splits on \(X_j\),

  4. -
  5. mse_increase (regression) – mean increase of mean squared error after \(X_j\) is permuted,

  6. -
  7. node_purity_increase (regression) – mean node purity increase by splits on \(X_j\), as measured by the decrease in sum of squares,

  8. -
  9. mean_minimal_depth – mean minimal depth calculated in one of three ways specified by the parameter mean_sample,

  10. -
  11. no_of_trees – total number of trees in which a split on \(X_j\) occurs,

  12. -
  13. no_of_nodes – total number of nodes that use \(X_j\) for splitting (it is usually equal to no_of_trees if trees are shallow),

  14. -
  15. times_a_root – total number of trees in which \(X_j\) is used for splitting the root node (i.e., the whole sample is divided into two based on the value of \(X_j\)),

  16. -
  17. p_value\(p\)-value for the one-sided binomial test using the following distribution: \[Bin(\texttt{no_of_nodes},\ \mathbf{P}(\text{node splits on } X_j)),\] where we calculate the probability of split on \(X_j\) as if \(X_j\) was uniformly drawn from the \(r\) candidate variables \[\mathbf{P}(\text{node splits on } X_j) = \mathbf{P}(X_j \text{ is a candidate})\cdot\mathbf{P}(X_j \text{ is selected}) = \frac{r}{p}\cdot \frac{1}{r} = \frac{1}{p}.\] This test tells us whether the observed number of successes (number of nodes in which \(X_j\) was used for splitting) exceeds the theoretical number of successes if they were random (i.e. following the binomial distribution given above).

  18. +
  19. accuracy_decrease (classification) – mean decrease +of prediction accuracy after \(X_j\) is +permuted,

  20. +
  21. gini_decrease (classification) – mean decrease in +the Gini index of node impurity (i.e. increase of node purity) by splits +on \(X_j\),

  22. +
  23. mse_increase (regression) – mean increase of mean +squared error after \(X_j\) is +permuted,

  24. +
  25. node_purity_increase (regression) – mean node purity +increase by splits on \(X_j\), as +measured by the decrease in sum of squares,

  26. +
  27. mean_minimal_depth – mean minimal depth calculated +in one of three ways specified by the parameter +mean_sample,

  28. +
  29. no_of_trees – total number of trees in which a split +on \(X_j\) occurs,

  30. +
  31. no_of_nodes – total number of nodes that use \(X_j\) for splitting (it is usually equal to +no_of_trees if trees are shallow),

  32. +
  33. times_a_root – total number of trees in which \(X_j\) is used for splitting the root node +(i.e., the whole sample is divided into two based on the value of \(X_j\)),

  34. +
  35. p_value\(p\)-value for the one-sided binomial test +using the following distribution: \[Bin(\texttt{no_of_nodes},\ \mathbf{P}(\text{node +splits on } X_j)),\] where we calculate the probability of split +on \(X_j\) as if \(X_j\) was uniformly drawn from the \(r\) candidate variables \[\mathbf{P}(\text{node splits on } X_j) = +\mathbf{P}(X_j \text{ is a candidate})\cdot\mathbf{P}(X_j \text{ is +selected}) = \frac{r}{p}\cdot \frac{1}{r} = \frac{1}{p}.\] This +test tells us whether the observed number of successes (number of nodes +in which \(X_j\) was used for +splitting) exceeds the theoretical number of successes if they were +random (i.e. following the binomial distribution given above).

-

Measures (a)-(d) are calculated by the randomForest package so need only to be extracted from our forest object if option localImp = TRUE was used for growing the forest (we assume this is the case). Note that measures (a) and (c) are based on the decrease in predictive accuracy of the forest after perturbation of the variable, (b) and (d) are based on changes in node purity after splits on the variable and (e)-(i) are based on the structure of the forest.

-

The function measure_importance allows you to specify the method of calculating mean minimal depth (mean_sample parameter, default "top_trees") and the measures to be calculated as a character vector a subset of names of measures given above (measures parameter, default to NULL leads to calculating all measures).

-
-

-Multi-way importance plot

-

Below we present the result of plot_multi_way_importance for the default values of x_measure and y_measure, which specify measures to use on \(x\) and \(y\)-axis, and the size of points reflects the number of nodes split on the variable. For problems with many variables we can restrict the plot to only those used for splitting in at least min_no_of_trees trees. By default 10 top variables in the plot are highlighted in blue and labeled (no_of_labels) – these are selected using the function important_variables, i.e. using the sum of rankings based on importance measures used in the plot (more variables may be labeled if ties occur).

+

Measures (a)-(d) are calculated by the randomForest +package so need only to be extracted from our forest object +if option localImp = TRUE was used for growing the forest +(we assume this is the case). Note that measures (a) and (c) are based +on the decrease in predictive accuracy of the forest after perturbation +of the variable, (b) and (d) are based on changes in node purity after +splits on the variable and (e)-(i) are based on the structure of the +forest.

+

The function measure_importance allows you to specify +the method of calculating mean minimal depth (mean_sample +parameter, default "top_trees") and the measures to be +calculated as a character vector a subset of names of measures given +above (measures parameter, default to NULL +leads to calculating all measures).

+
+

Multi-way importance plot +

+

Below we present the result of plot_multi_way_importance +for the default values of x_measure and +y_measure, which specify measures to use on \(x\) and \(y\)-axis, and the size of points reflects +the number of nodes split on the variable. For problems with many +variables we can restrict the plot to only those used for splitting in +at least min_no_of_trees trees. By default 10 top variables +in the plot are highlighted in blue and labeled +(no_of_labels) – these are selected using the function +important_variables, i.e. using the sum of rankings based +on importance measures used in the plot (more variables may be labeled +if ties occur).

-# plot_multi_way_importance(forest, size_measure = "no_of_nodes") # gives the same result as below but takes longer
-plot_multi_way_importance(importance_frame, size_measure = "no_of_nodes")
+# plot_multi_way_importance(forest, size_measure = "no_of_nodes") # gives the same result as below but takes longer +plot_multi_way_importance(importance_frame, size_measure = "no_of_nodes")

-

Observe the marked negative relation between times_a_root and mean_min_depth. Also, the superiority of lstat and rm is clear in all three dimensions plotted (though it is not clear which of the two is better). Further, we present the multi-way importance plot for a different set of importance measures: increase of mean squared error after permutation (\(x\)-axis), increase in the node purity index (\(y\)-axis) and levels of significance (color of points). We also set no_of_labels to five so that only five top variables will be highlighted (as ties occur, six are eventually labeled).

+

Observe the marked negative relation between +times_a_root and mean_min_depth. Also, the +superiority of lstat and rm is clear in all +three dimensions plotted (though it is not clear which of the two is +better). Further, we present the multi-way importance plot for a +different set of importance measures: increase of mean squared error +after permutation (\(x\)-axis), +increase in the node purity index (\(y\)-axis) and levels of significance (color +of points). We also set no_of_labels to five so that only +five top variables will be highlighted (as ties occur, six are +eventually labeled).

-plot_multi_way_importance(importance_frame, x_measure = "mse_increase", y_measure = "node_purity_increase", size_measure = "p_value", no_of_labels = 5)
+plot_multi_way_importance(importance_frame, x_measure = "mse_increase", y_measure = "node_purity_increase", size_measure = "p_value", no_of_labels = 5)

-

As in the previous plot, the two measures used as coordinates seem correlated, but in this case this is somewhat more surprising as one is connected to the structure of the forest and the other to its prediction, whereas in the previous plot both measures reflected the structure. Also, in this plot we see that although lstat and rm are similar in terms of node purity increase and \(p\)-value, the former is markedly better if we look at the increase in MSE. Interestingly, nox and indus are quite good when it comes to the two measures reflected on the axes, but are not significant according to our \(p\)-value, which is a derivative of the number of nodes that use a variable for splitting.

+

As in the previous plot, the two measures used as coordinates seem +correlated, but in this case this is somewhat more surprising as one is +connected to the structure of the forest and the other to its +prediction, whereas in the previous plot both measures reflected the +structure. Also, in this plot we see that although lstat +and rm are similar in terms of node purity increase and +\(p\)-value, the former is markedly +better if we look at the increase in MSE. Interestingly, +nox and indus are quite good when it comes to +the two measures reflected on the axes, but are not significant +according to our \(p\)-value, which is +a derivative of the number of nodes that use a variable for +splitting.

-
-

-Compare measures using ggpairs

-

Generally, the multi-way importance plot offers a wide variety of possibilities so it can be hard to select the most informative one. One idea of overcoming this obstacle is to first explore relations between different importance measures to then select three that least agree with each other and use them in the multi-way importance plot to select top variables. The first is easily done by plotting selected importance measures pairwise against each other using plot_importance_ggpairs as below. One could of course include all seven measures in the plot but by default \(p\)-value and the number of trees are excluded as both carry similar information as the number of nodes.

+
+

Compare measures using ggpairs +

+

Generally, the multi-way importance plot offers a wide variety of +possibilities so it can be hard to select the most informative one. One +idea of overcoming this obstacle is to first explore relations between +different importance measures to then select three that least agree with +each other and use them in the multi-way importance plot to select top +variables. The first is easily done by plotting selected importance +measures pairwise against each other using +plot_importance_ggpairs as below. One could of course +include all seven measures in the plot but by default \(p\)-value and the number of trees are +excluded as both carry similar information as the number of nodes.

-# plot_importance_ggpairs(forest) # gives the same result as below but takes longer
-plot_importance_ggpairs(importance_frame)
+# plot_importance_ggpairs(forest) # gives the same result as below but takes longer +plot_importance_ggpairs(importance_frame)

-

We can see that all depicted measures are highly correlated (of course the correlation of any measure with mean minimal depth is negative as the latter is lowest for best variables), but some less than others. Moreover, regardless of which measures we compare, there always seem to be two points that stand out and these most likely correspond to lstat and rm (to now for sure we could just examine the importance_frame).

+

We can see that all depicted measures are highly correlated (of +course the correlation of any measure with mean minimal depth is +negative as the latter is lowest for best variables), but some less than +others. Moreover, regardless of which measures we compare, there always +seem to be two points that stand out and these most likely correspond to +lstat and rm (to now for sure we could just +examine the importance_frame).

-
-

-Compare different rankings

-

In addition to scatter plots and correlation coefficients, the ggpairs plot also depicts density estimate for each importance measure – all of which are in this case very skewed. An attempt to eliminate this feature by plotting rankings instead of raw measures is implemented in the function plot_importance_rankings that also includes the fitted LOESS curve in each plot.

+
+

Compare different rankings +

+

In addition to scatter plots and correlation coefficients, the +ggpairs plot also depicts density estimate for each importance measure – +all of which are in this case very skewed. An attempt to eliminate this +feature by plotting rankings instead of raw measures is implemented in +the function plot_importance_rankings that also includes +the fitted LOESS curve in each plot.

-# plot_importance_rankings(forest) # gives the same result as below but takes longer
-plot_importance_rankings(importance_frame)
+# plot_importance_rankings(forest) # gives the same result as below but takes longer +plot_importance_rankings(importance_frame)

-

The above density estimates show that skewness was eliminated for all of our importance measures (this is not always the case, e.g., when ties in rankings are frequent, and this is likely for discrete importance measures such as times_a_root, then the distribution of the ranking will also be skewed).

-

When comparing the rankings in the above plot we can see that two pairs of measures almost exactly agree in their rankings of variables: mean_min_depth vs. mse_increase and mse_increase vs. node_purity_increase. In applications where there are many variables, the LOESS curve may be the main takeaway from this plot (if points fill in the whole plotting area and this is likely if the distributions of measures are close to uniform).

+

The above density estimates show that skewness was eliminated for all +of our importance measures (this is not always the case, e.g., when ties +in rankings are frequent, and this is likely for discrete importance +measures such as times_a_root, then the distribution of the +ranking will also be skewed).

+

When comparing the rankings in the above plot we can see that two +pairs of measures almost exactly agree in their rankings of variables: +mean_min_depth vs. mse_increase and +mse_increase vs. node_purity_increase. In +applications where there are many variables, the LOESS curve may be the +main takeaway from this plot (if points fill in the whole plotting area +and this is likely if the distributions of measures are close to +uniform).

-
-

-Variable interactions

-
-

-Conditional minimal depth

-

After selecting a set of most important variables we can investigate interactions with respect to them, i.e. splits appearing in maximal subtrees with respect to one of the variables selected. To extract the names of 5 most important variables according to both the mean minimal depth and number of trees in which a variable appeared, we pass our importance_frame to the function important_variables as follows:

+
+

Variable interactions +

+
+

Conditional minimal depth +

+

After selecting a set of most important variables we can investigate +interactions with respect to them, i.e. splits appearing in maximal +subtrees with respect to one of the variables selected. To extract the +names of 5 most important variables according to both the mean minimal +depth and number of trees in which a variable appeared, we pass our +importance_frame to the function +important_variables as follows:

-# (vars <- important_variables(forest, k = 5, measures = c("mean_min_depth", "no_of_trees"))) # gives the same result as below but takes longer
-(vars <- important_variables(importance_frame, k = 5, measures = c("mean_min_depth", "no_of_trees")))
-
## [1] "lstat" "rm"    "crim"  "nox"   "dis"
-

We pass the result together with or forest to the min_depth_interactions function to obtain a data frame containing information on mean conditional minimal depth of variables with respect to each element of vars (missing values are filled analogously as for unconditional minimal depth, in one of three ways specified by mean_sample). If we would not specify the vars argument then the vector of conditioning variables would be by default obtained using important_variables(measure_importance(forest)).

+# (vars <- important_variables(forest, k = 5, measures = c("mean_min_depth", "no_of_trees"))) # gives the same result as below but takes longer +(vars <- important_variables(importance_frame, k = 5, measures = c("mean_min_depth", "no_of_trees")))
+
## [1] "lstat" "rm"    "crim"  "nox"   "dis"
+

We pass the result together with or forest to the +min_depth_interactions function to obtain a data frame +containing information on mean conditional minimal depth of variables +with respect to each element of vars (missing values are +filled analogously as for unconditional minimal depth, in one of three +ways specified by mean_sample). If we would not specify the +vars argument then the vector of conditioning variables +would be by default obtained using +important_variables(measure_importance(forest)).

-# interactions_frame <- min_depth_interactions(forest, vars)
-# save(interactions_frame, file = "interactions_frame.rda")
-load("interactions_frame.rda")
-head(interactions_frame[order(interactions_frame$occurrences, decreasing = TRUE), ])
-
##    variable root_variable mean_min_depth occurrences interaction
-## 53       rm         lstat       1.179381         485    lstat:rm
-## 18     crim         lstat       1.934738         478  lstat:crim
-## 3       age         lstat       2.388948         475   lstat:age
-## 23      dis         lstat       1.786887         475   lstat:dis
-## 33    lstat         lstat       1.584338         474 lstat:lstat
-## 8     black         lstat       2.870078         468 lstat:black
-##    uncond_mean_min_depth
-## 53                 1.346
-## 18                 2.386
-## 3                  3.308
-## 23                 2.600
-## 33                 1.288
-## 8                  3.512
-

Then, we pass our interactions_frame to the plotting function plot_min_depth_interactions and obtain the following:

+# interactions_frame <- min_depth_interactions(forest, vars) +# save(interactions_frame, file = "interactions_frame.rda") +load("interactions_frame.rda") +head(interactions_frame[order(interactions_frame$occurrences, decreasing = TRUE), ])
+
##    variable root_variable mean_min_depth occurrences interaction
+## 53       rm         lstat       1.179381         485    lstat:rm
+## 18     crim         lstat       1.934738         478  lstat:crim
+## 3       age         lstat       2.388948         475   lstat:age
+## 23      dis         lstat       1.786887         475   lstat:dis
+## 33    lstat         lstat       1.584338         474 lstat:lstat
+## 8     black         lstat       2.870078         468 lstat:black
+##    uncond_mean_min_depth
+## 53                 1.346
+## 18                 2.386
+## 3                  3.308
+## 23                 2.600
+## 33                 1.288
+## 8                  3.512
+

Then, we pass our interactions_frame to the plotting +function plot_min_depth_interactions and obtain the +following:

-# plot_min_depth_interactions(forest) # calculates the interactions_frame for default settings so may give different results than the function below depending on our settings and takes more time
-plot_min_depth_interactions(interactions_frame)
+# plot_min_depth_interactions(forest) # calculates the interactions_frame for default settings so may give different results than the function below depending on our settings and takes more time +plot_min_depth_interactions(interactions_frame)

-

Note that the interactions are ordered by decreasing number of occurrences – the most frequent one, lstat:rm, is also the one with minimal mean conditional minimal depth. Remarkably, the unconditional mean minimal depth of rm in the forest is almost equal to its mean minimal depth across maximal subtrees with lstat as the root variable.

-

Generally, the plot contains much information and can be interpreted in many ways but always bear in mind the method used for calculating the conditional (mean_sample parameter) and unconditional (uncond_mean_sample parameter) mean minimal depth. Using the default "top_trees" penalizes interactions that occur less frequently than the most frequent one. Of course, one can switch between "all_trees", "top_trees" and "relevant_trees" for calculating the mean of both the conditional and unconditional minimal depth but each of them has its drawbacks and we favour using "top_trees" (the default). However, as plot_min_depth_interactions plots interactions by decreasing frequency the major drawback of calculating the mean only for relevant variables vanishes as interactions appearing for example only once but with conditional depth 0 will not be included in the plot anyway. Thus, we repeat the computation of means using "relevant_trees" and get the following result:

+

Note that the interactions are ordered by decreasing number of +occurrences – the most frequent one, lstat:rm, is also the +one with minimal mean conditional minimal depth. Remarkably, the +unconditional mean minimal depth of rm in the forest is +almost equal to its mean minimal depth across maximal subtrees with +lstat as the root variable.

+

Generally, the plot contains much information and can be interpreted +in many ways but always bear in mind the method used for calculating the +conditional (mean_sample parameter) and unconditional +(uncond_mean_sample parameter) mean minimal depth. Using +the default "top_trees" penalizes interactions that occur +less frequently than the most frequent one. Of course, one can switch +between "all_trees", "top_trees" and +"relevant_trees" for calculating the mean of both the +conditional and unconditional minimal depth but each of them has its +drawbacks and we favour using "top_trees" (the default). +However, as plot_min_depth_interactions plots interactions +by decreasing frequency the major drawback of calculating the mean only +for relevant variables vanishes as interactions appearing for example +only once but with conditional depth 0 will not be included in the plot +anyway. Thus, we repeat the computation of means using +"relevant_trees" and get the following result:

-# interactions_frame <- min_depth_interactions(forest, vars, mean_sample = "relevant_trees", uncond_mean_sample = "relevant_trees")
-# save(interactions_frame, file = "interactions_frame_relevant.rda")
-load("interactions_frame_relevant.rda")
-plot_min_depth_interactions(interactions_frame)
+# interactions_frame <- min_depth_interactions(forest, vars, mean_sample = "relevant_trees", uncond_mean_sample = "relevant_trees") +# save(interactions_frame, file = "interactions_frame_relevant.rda") +load("interactions_frame_relevant.rda") +plot_min_depth_interactions(interactions_frame)

-

Comparing this plot with the previous one we see that removing penalization of missing values lowers the mean conditional minimal depth of all interactions except the most frequent one. Now, in addition to the frequent ones, some of the less frequent like rm:tax stand out.

+

Comparing this plot with the previous one we see that removing +penalization of missing values lowers the mean conditional minimal depth +of all interactions except the most frequent one. Now, in addition to +the frequent ones, some of the less frequent like rm:tax +stand out.

-
-

-Prediction of the forest on a grid

-

To further investigate the most frequent interaction lstat:rm we use the function plot_predict_interaction to plot the prediction of our forest on a grid of values for the components of each interaction. The function requires the forest, training data, variable to use on \(x\) and \(y\)-axis, respectively. In addition, one can also decrease the number of points in both dimensions of the grid from the default of 100 in case of insufficient memory using the parameter grid.

+
+

Prediction of the forest on a grid +

+

To further investigate the most frequent interaction +lstat:rm we use the function +plot_predict_interaction to plot the prediction of our +forest on a grid of values for the components of each interaction. The +function requires the forest, training data, variable to use on \(x\) and \(y\)-axis, respectively. In addition, one +can also decrease the number of points in both dimensions of the grid +from the default of 100 in case of insufficient memory using the +parameter grid.

-plot_predict_interaction(forest, Boston, "rm", "lstat")
+plot_predict_interaction(forest, Boston, "rm", "lstat")

-

In the above plot we can clearly see the effect of interaction: the predicted median price is highest when lstat is low and rm is high and low when the reverse is true. To further investigate the effect of interactions we could plot other frequent ones on a grid.

+

In the above plot we can clearly see the effect of interaction: the +predicted median price is highest when lstat is low and +rm is high and low when the reverse is true. To further +investigate the effect of interactions we could plot other frequent ones +on a grid.

-
-

-Explain the forest

-

The explain_forest() function is the flagship function of the randomForestExplainer package, as it takes your random forest and produces a html report that summarizes all basic results obtained for the forest with the new package. Below, we show how to run this function with default settings (we only supply the forest, training data, set interactions = TRUE contrary to the default to show full functionality and decrease the grid for prediction plots in our most computationally-intense examples) for our data set.

+
+

Explain the forest +

+

The explain_forest() function is the flagship function +of the randomForestExplainer package, as it takes your +random forest and produces a html report that summarizes all basic +results obtained for the forest with the new package. Below, we show how +to run this function with default settings (we only supply the forest, +training data, set interactions = TRUE contrary to the +default to show full functionality and decrease the grid for prediction +plots in our most computationally-intense examples) for our data +set.

-explain_forest(forest, interactions = TRUE, data = Boston)
-

To see the resulting HTML document click here: Boston forest summary

-

For additional examples see: initial vignette.

+explain_forest(forest, interactions = TRUE, data = Boston)
+

To see the resulting HTML document click here: Boston +forest summary

+

For additional examples see: initial +vignette.

@@ -356,11 +594,13 @@

diff --git a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-10-1.png index 386437e..abedabe 100644 Binary files a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-10-1.png and b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-11-1.png b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-11-1.png index fa1046a..0b0db22 100644 Binary files a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-11-1.png and b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-11-1.png differ diff --git a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-12-1.png b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-12-1.png index 4bc9520..7a37d07 100644 Binary files a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-12-1.png and b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-12-1.png differ diff --git a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-15-1.png b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-15-1.png index e150412..20e62d0 100644 Binary files a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-15-1.png and b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-15-1.png differ diff --git a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-16-1.png b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-16-1.png index 90e1118..188ad70 100644 Binary files a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-16-1.png and b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-16-1.png differ diff --git a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-17-1.png b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-17-1.png index 55db853..f8efa73 100644 Binary files a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-17-1.png and b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-17-1.png differ diff --git a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-6-1.png index 029db5b..4308586 100644 Binary files a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-7-1.png index 4766e96..6460d37 100644 Binary files a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-7-1.png and b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-9-1.png index aaeda2d..8db4b59 100644 Binary files a/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-9-1.png and b/docs/articles/randomForestExplainer_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/authors.html b/docs/authors.html index 9e41a8b..c574cd3 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -1,88 +1,16 @@ - - - - - - - -Authors • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Authors and Citation • randomForestExplainer - - - - - - - - -
-
-
- -
+
- @@ -161,22 +97,18 @@

Authors

-
- +
- - - + diff --git a/docs/index.html b/docs/index.html index c2d868e..8ec765d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -48,20 +48,14 @@
- - -
+
-
-

-randomForestExplainer 0.10.0 2019-09-18 -

-
-

-New features

-
    -
  • Added support for ranger forests.
  • +
    + +
    • Remove dependency on reshape2 in favour of tidyr (@olivroy, #33)

    • +
    • Silence deprecation warnings from ggplot2 and dplyr (@olivroy, #29)

    • +
    • Use testthat 3rd edition. (@olivroy, #33)

    • +
    +
    + +
    +
    + +
    +

    New features

    +
    • Added support for ranger forests.
    • Added support for unsupervised randomForest.
    • Added tests for most functions.
    • -
    -
    -
    -

    -Bug fixes

    -
      -
    • Fixed bug for explain_forest not finding templates.
    • -
    • Added more intuitive error message for explain_forest when local importance is absent.
    • -
    -
    +
+
+

Bug fixes

+
+
- - - - + diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index f2736aa..b2ffd12 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,7 +1,7 @@ -pandoc: 2.11.4 -pkgdown: 1.6.1 +pandoc: 3.1.8 +pkgdown: 2.0.7 pkgdown_sha: ~ articles: randomForestExplainer: randomForestExplainer.html -last_built: 2021-06-30T22:14Z +last_built: 2024-01-13T18:15Z diff --git a/docs/reference/Rplot001.png b/docs/reference/Rplot001.png index 1a63140..8319167 100644 Binary files a/docs/reference/Rplot001.png and b/docs/reference/Rplot001.png differ diff --git a/docs/reference/Rplot002.png b/docs/reference/Rplot002.png index be2a8e9..e2d981e 100644 Binary files a/docs/reference/Rplot002.png and b/docs/reference/Rplot002.png differ diff --git a/docs/reference/explain_forest.html b/docs/reference/explain_forest.html index 0b6560e..ae6d329 100644 --- a/docs/reference/explain_forest.html +++ b/docs/reference/explain_forest.html @@ -1,89 +1,16 @@ - - - - - - - -Explain a random forest — explain_forest • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Explain a random forest — explain_forest • randomForestExplainer - - - - - - - - +
-
- -
- -
+
@@ -147,90 +63,88 @@

Explain a random forest

Explains a random forest in a html document using plots created by randomForestExplainer

-
explain_forest(
-  forest,
-  path = NULL,
-  interactions = FALSE,
-  data = NULL,
-  vars = NULL,
-  no_of_pred_plots = 3,
-  pred_grid = 100,
-  measures = NULL
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
forest

A randomForest object created with the option localImp = TRUE

path

Path to write output html to

interactions

Logical value: should variable interactions be considered (this may be time-consuming)

data

The data frame on which forest was trained - necessary if interactions = TRUE

vars

A character vector with variables with respect to which interactions will be considered if NULL then they will be selected using the important_variables() function

no_of_pred_plots

The number of most frequent interactions of numeric variables to plot predictions for

pred_grid

The number of points on the grid of plot_predict_interaction (decrease in case memory problems)

measures

A character vector specifying the importance measures to be used for plotting ggpairs

- -

Value

- -

A html document. If path is not specified, this document will be "Your_forest_explained.html" in your working directory

- -

Examples

-
if (FALSE) { -forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE) -explain_forest(forest, interactions = TRUE) -} - -
+
+
explain_forest(
+  forest,
+  path = NULL,
+  interactions = FALSE,
+  data = NULL,
+  vars = NULL,
+  no_of_pred_plots = 3,
+  pred_grid = 100,
+  measures = NULL
+)
+
+ +
+

Arguments

+
forest
+

A randomForest object created with the option localImp = TRUE

+ + +
path
+

Path to write output html to

+ + +
interactions
+

Logical value: should variable interactions be considered (this may be time-consuming)

+ + +
data
+

The data frame on which forest was trained - necessary if interactions = TRUE

+ + +
vars
+

A character vector with variables with respect to which interactions will be considered if NULL then they will be selected using the important_variables() function

+ + +
no_of_pred_plots
+

The number of most frequent interactions of numeric variables to plot predictions for

+ + +
pred_grid
+

The number of points on the grid of plot_predict_interaction (decrease in case memory problems)

+ + +
measures
+

A character vector specifying the importance measures to be used for plotting ggpairs

+ +
+
+

Value

+ + +

A html document. If path is not specified, this document will be "Your_forest_explained.html" in your working directory

+
+ +
+

Examples

+
if (FALSE) {
+forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE)
+explain_forest(forest, interactions = TRUE)
+}
+
+
+
+
- - - - + diff --git a/docs/reference/important_variables.html b/docs/reference/important_variables.html index fb133bf..63d95d7 100644 --- a/docs/reference/important_variables.html +++ b/docs/reference/important_variables.html @@ -1,89 +1,16 @@ - - - - - - - -Extract k most important variables in a random forest — important_variables • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Extract k most important variables in a random forest — important_variables • randomForestExplainer - - - - - - - - +
-
- -
- -
+
@@ -147,68 +63,67 @@

Extract k most important variables in a random forest

Get the names of k variables with highest sum of rankings based on the specified importance measures

-
important_variables(
-  importance_frame,
-  k = 15,
-  measures = names(importance_frame)[2:min(5, ncol(importance_frame))],
-  ties_action = "all"
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
importance_frame

A result of using the function measure_importance() to a random forest or a randomForest object

k

The number of variables to extract

measures

A character vector specifying the measures of importance to be used

ties_action

One of three: c("none", "all", "draw"); specifies which variables to pick when ties occur. When set to "none" we may get less than k variables, when "all" we may get more and "draw" makes us get exactly k.

- -

Value

- -

A character vector with names of k variables with highest sum of rankings

- -

Examples

-
forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE, ntree = 300) -important_variables(measure_importance(forest), k = 2) -
#> [1] "Petal.Length" "Petal.Width"
-
+
+
important_variables(
+  importance_frame,
+  k = 15,
+  measures = names(importance_frame)[2:min(5, ncol(importance_frame))],
+  ties_action = "all"
+)
+
+ +
+

Arguments

+
importance_frame
+

A result of using the function measure_importance() to a random forest or a randomForest object

+ + +
k
+

The number of variables to extract

+ + +
measures
+

A character vector specifying the measures of importance to be used

+ + +
ties_action
+

One of three: c("none", "all", "draw"); specifies which variables to pick when ties occur. When set to "none" we may get less than k variables, when "all" we may get more and "draw" makes us get exactly k.

+ +
+
+

Value

+ + +

A character vector with names of k variables with highest sum of rankings

+
+ +
+

Examples

+
forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE, ntree = 300)
+important_variables(measure_importance(forest), k = 2)
+#> [1] "Petal.Width"  "Petal.Length"
+
+
+
+
- - - - + diff --git a/docs/reference/index.html b/docs/reference/index.html index 5b6fc65..47188d7 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -1,88 +1,16 @@ - - - - - - - -Function reference • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Function reference • randomForestExplainer - - - - - - - - +
-
- -
- -
+
- - - - - - - - - - -
-

All functions

+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+

All functions

+

explain_forest()

Explain a random forest

+

important_variables()

Extract k most important variables in a random forest

+

measure_importance()

Importance of variables in a random forest

+

min_depth_distribution()

Calculate minimal depth distribution of a random forest

+

min_depth_interactions()

Calculate mean conditional minimal depth

+

plot_importance_ggpairs()

Plot importance measures with ggpairs

+

plot_importance_rankings()

Plot importance measures rankings with ggpairs

+

plot_min_depth_distribution()

Plot the distribution of minimal depth in a random forest

+

plot_min_depth_interactions()

Plot the top mean conditional minimal depth

+

plot_multi_way_importance()

Multi-way importance plot

+

plot_predict_interaction()

Plot the prediction of the forest for a grid of values of two numerical variables

- +
+
-
- +
- - - + diff --git a/docs/reference/measure_importance.html b/docs/reference/measure_importance.html index b6ca28a..9e6ac79 100644 --- a/docs/reference/measure_importance.html +++ b/docs/reference/measure_importance.html @@ -1,89 +1,16 @@ - - - - - - - -Importance of variables in a random forest — measure_importance • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Importance of variables in a random forest — measure_importance • randomForestExplainer - - - - - - - - +
-
- -
- -
+
@@ -147,72 +63,71 @@

Importance of variables in a random forest

Get a data frame with various measures of importance of variables in a random forest

-
measure_importance(forest, mean_sample = "top_trees", measures = NULL)
- -

Arguments

- - - - - - - - - - - - - - -
forest

A random forest produced by the function randomForest with option localImp = TRUE

mean_sample

The sample of trees on which mean minimal depth is calculated, possible values are "all_trees", "top_trees", "relevant_trees"

measures

A vector of names of importance measures to be calculated - if equal to NULL then all are calculated; +

+
measure_importance(forest, mean_sample = "top_trees", measures = NULL)
+
+ +
+

Arguments

+
forest
+

A random forest produced by the function randomForest with option localImp = TRUE

+ + +
mean_sample
+

The sample of trees on which mean minimal depth is calculated, possible values are "all_trees", "top_trees", "relevant_trees"

+ + +
measures
+

A vector of names of importance measures to be calculated - if equal to NULL then all are calculated; if "p_value" is to be calculated then "no_of_nodes" will be too. Suitable measures for classification forests are: mean_min_depth, accuracy_decrease, gini_decrease, no_of_nodes, times_a_root. For regression forests choose from: mean_min_depth, -mse_increase, node_purity_increase, no_of_nodes, times_a_root.

- -

Value

- -

A data frame with rows corresponding to variables and columns to various measures of importance of variables

- -

Examples

-
forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE, ntree = 300) -measure_importance(forest) -
#> variable mean_min_depth no_of_nodes accuracy_decrease gini_decrease -#> 1 Petal.Length 1.1114865 749 0.298860983 42.010102 -#> 2 Petal.Width 0.9932432 775 0.310185955 43.803248 -#> 3 Sepal.Length 2.0128041 493 0.033657157 11.235496 -#> 4 Sepal.Width 3.2915203 356 0.007638947 2.196532 -#> no_of_trees times_a_root p_value -#> 1 296 116 3.594621e-13 -#> 2 296 124 3.550723e-17 -#> 3 265 60 9.999994e-01 -#> 4 215 0 1.000000e+00
-
+mse_increase, node_purity_increase, no_of_nodes, times_a_root.

+ +
+
+

Value

+ + +

A data frame with rows corresponding to variables and columns to various measures of importance of variables

+
+ +
+

Examples

+
forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE, ntree = 300)
+measure_importance(forest)
+#>       variable mean_min_depth no_of_nodes accuracy_decrease gini_decrease
+#> 1 Petal.Length      0.8993289         796       0.332686952     46.623867
+#> 2  Petal.Width      1.1048546         721       0.272628994     39.578597
+#> 3 Sepal.Length      2.2073714         499       0.039987377     10.525047
+#> 4  Sepal.Width      3.2914989         348       0.009315119      2.478699
+#>   no_of_trees times_a_root      p_value
+#> 1         298          132 2.687474e-21
+#> 2         296          107 8.694212e-10
+#> 3         251           61 9.999961e-01
+#> 4         218            0 1.000000e+00
+
+
+
+
- - - - + diff --git a/docs/reference/min_depth_distribution.html b/docs/reference/min_depth_distribution.html index 7505272..26dd6bc 100644 --- a/docs/reference/min_depth_distribution.html +++ b/docs/reference/min_depth_distribution.html @@ -1,89 +1,16 @@ - - - - - - - -Calculate minimal depth distribution of a random forest — min_depth_distribution • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Calculate minimal depth distribution of a random forest — min_depth_distribution • randomForestExplainer - - - - - - - - +
-
- -
- -
+
@@ -147,738 +63,719 @@

Calculate minimal depth distribution of a random forest

Get minimal depth values for all trees in a random forest

-
min_depth_distribution(forest)
+
+
min_depth_distribution(forest)
+
-

Arguments

- - - - - - -
forest

A randomForest or ranger object

+
+

Arguments

+
forest
+

A randomForest or ranger object

-

Value

+
+
+

Value

+ -

A data frame with the value of minimal depth for every variable in every tree

+

A data frame with the value of minimal depth for every variable in every tree

+
-

Examples

-
min_depth_distribution(randomForest::randomForest(Species ~ ., data = iris, ntree = 100)) -
#> tree variable minimal_depth -#> 1 1 Petal.Length 1 -#> 2 1 Petal.Width 0 -#> 3 1 Sepal.Length 4 -#> 4 1 Sepal.Width 2 -#> 5 2 Petal.Length 0 -#> 6 2 Petal.Width 2 -#> 7 2 Sepal.Length 2 -#> 8 3 Petal.Length 2 -#> 9 3 Petal.Width 0 -#> 10 3 Sepal.Width 3 -#> 11 4 Petal.Length 0 -#> 12 4 Petal.Width 1 -#> 13 4 Sepal.Length 2 -#> 14 4 Sepal.Width 3 -#> 15 5 Petal.Length 2 -#> 16 5 Petal.Width 0 -#> 17 5 Sepal.Length 1 -#> 18 5 Sepal.Width 2 -#> 19 6 Petal.Length 0 -#> 20 6 Petal.Width 1 -#> 21 6 Sepal.Length 3 -#> 22 6 Sepal.Width 3 -#> 23 7 Petal.Length 0 -#> 24 7 Petal.Width 1 -#> 25 7 Sepal.Length 2 -#> 26 7 Sepal.Width 4 -#> 27 8 Petal.Length 0 -#> 28 8 Petal.Width 2 -#> 29 8 Sepal.Width 3 -#> 30 9 Petal.Length 5 -#> 31 9 Petal.Width 0 -#> 32 9 Sepal.Length 2 -#> 33 9 Sepal.Width 3 -#> 34 10 Petal.Length 0 -#> 35 10 Petal.Width 2 -#> 36 10 Sepal.Length 4 -#> 37 10 Sepal.Width 3 -#> 38 11 Petal.Length 1 -#> 39 11 Petal.Width 0 -#> 40 11 Sepal.Length 4 -#> 41 11 Sepal.Width 2 -#> 42 12 Petal.Length 2 -#> 43 12 Petal.Width 0 -#> 44 12 Sepal.Length 1 -#> 45 12 Sepal.Width 4 -#> 46 13 Petal.Length 2 -#> 47 13 Petal.Width 0 -#> 48 13 Sepal.Length 3 -#> 49 13 Sepal.Width 2 -#> 50 14 Petal.Length 0 -#> 51 14 Petal.Width 1 -#> 52 14 Sepal.Width 3 -#> 53 15 Petal.Length 0 -#> 54 15 Petal.Width 4 -#> 55 15 Sepal.Length 4 -#> 56 15 Sepal.Width 2 -#> 57 16 Petal.Length 1 -#> 58 16 Petal.Width 1 -#> 59 16 Sepal.Length 0 -#> 60 16 Sepal.Width 2 -#> 61 17 Petal.Length 2 -#> 62 17 Petal.Width 0 -#> 63 18 Petal.Length 0 -#> 64 18 Petal.Width 1 -#> 65 18 Sepal.Length 3 -#> 66 18 Sepal.Width 3 -#> 67 19 Petal.Length 2 -#> 68 19 Petal.Width 0 -#> 69 20 Petal.Length 4 -#> 70 20 Petal.Width 0 -#> 71 20 Sepal.Length 2 -#> 72 20 Sepal.Width 5 -#> 73 21 Petal.Length 1 -#> 74 21 Petal.Width 0 -#> 75 21 Sepal.Length 3 -#> 76 22 Petal.Length 0 -#> 77 22 Petal.Width 3 -#> 78 22 Sepal.Length 3 -#> 79 22 Sepal.Width 3 -#> 80 23 Petal.Length 0 -#> 81 23 Petal.Width 1 -#> 82 24 Petal.Length 3 -#> 83 24 Petal.Width 0 -#> 84 24 Sepal.Length 2 -#> 85 24 Sepal.Width 4 -#> 86 25 Petal.Length 0 -#> 87 25 Petal.Width 1 -#> 88 25 Sepal.Length 2 -#> 89 25 Sepal.Width 3 -#> 90 26 Petal.Length 1 -#> 91 26 Petal.Width 2 -#> 92 26 Sepal.Length 0 -#> 93 26 Sepal.Width 1 -#> 94 27 Petal.Length 1 -#> 95 27 Petal.Width 0 -#> 96 27 Sepal.Length 3 -#> 97 27 Sepal.Width 4 -#> 98 28 Petal.Length 0 -#> 99 28 Petal.Width 2 -#> 100 28 Sepal.Width 3 -#> 101 29 Petal.Length 1 -#> 102 29 Petal.Width 0 -#> 103 29 Sepal.Length 2 -#> 104 29 Sepal.Width 3 -#> 105 30 Petal.Length 0 -#> 106 30 Petal.Width 2 -#> 107 30 Sepal.Width 3 -#> 108 31 Petal.Length 2 -#> 109 31 Petal.Width 0 -#> 110 31 Sepal.Length 1 -#> 111 32 Petal.Length 0 -#> 112 32 Petal.Width 1 -#> 113 32 Sepal.Length 3 -#> 114 32 Sepal.Width 3 -#> 115 33 Petal.Length 1 -#> 116 33 Petal.Width 0 -#> 117 33 Sepal.Length 2 -#> 118 34 Petal.Length 0 -#> 119 34 Petal.Width 2 -#> 120 34 Sepal.Length 1 -#> 121 34 Sepal.Width 3 -#> 122 35 Petal.Length 2 -#> 123 35 Petal.Width 1 -#> 124 35 Sepal.Length 0 -#> 125 35 Sepal.Width 3 -#> 126 36 Petal.Length 2 -#> 127 36 Petal.Width 0 -#> 128 36 Sepal.Length 4 -#> 129 36 Sepal.Width 2 -#> 130 37 Petal.Length 1 -#> 131 37 Petal.Width 0 -#> 132 37 Sepal.Length 2 -#> 133 37 Sepal.Width 6 -#> 134 38 Petal.Length 2 -#> 135 38 Petal.Width 0 -#> 136 38 Sepal.Width 3 -#> 137 39 Petal.Length 0 -#> 138 39 Petal.Width 1 -#> 139 39 Sepal.Length 3 -#> 140 39 Sepal.Width 3 -#> 141 40 Petal.Length 0 -#> 142 40 Petal.Width 2 -#> 143 40 Sepal.Width 2 -#> 144 41 Petal.Length 1 -#> 145 41 Petal.Width 2 -#> 146 41 Sepal.Length 0 -#> 147 41 Sepal.Width 5 -#> 148 42 Petal.Length 2 -#> 149 42 Petal.Width 0 -#> 150 42 Sepal.Length 1 -#> 151 43 Petal.Length 1 -#> 152 43 Petal.Width 0 -#> 153 43 Sepal.Length 3 -#> 154 43 Sepal.Width 3 -#> 155 44 Petal.Length 0 -#> 156 44 Petal.Width 2 -#> 157 44 Sepal.Length 2 -#> 158 44 Sepal.Width 4 -#> 159 45 Petal.Length 0 -#> 160 45 Petal.Width 1 -#> 161 46 Petal.Length 1 -#> 162 46 Petal.Width 0 -#> 163 46 Sepal.Length 1 -#> 164 47 Petal.Length 0 -#> 165 47 Sepal.Length 2 -#> 166 47 Sepal.Width 3 -#> 167 48 Petal.Length 0 -#> 168 48 Petal.Width 3 -#> 169 48 Sepal.Length 1 -#> 170 48 Sepal.Width 4 -#> 171 49 Petal.Length 2 -#> 172 49 Petal.Width 0 -#> 173 49 Sepal.Length 1 -#> 174 49 Sepal.Width 2 -#> 175 50 Petal.Length 1 -#> 176 50 Petal.Width 0 -#> 177 51 Petal.Length 0 -#> 178 51 Petal.Width 2 -#> 179 51 Sepal.Length 1 -#> 180 51 Sepal.Width 3 -#> 181 52 Petal.Length 0 -#> 182 52 Petal.Width 3 -#> 183 52 Sepal.Length 1 -#> 184 52 Sepal.Width 2 -#> 185 53 Petal.Length 1 -#> 186 53 Petal.Width 0 -#> 187 53 Sepal.Width 4 -#> 188 54 Petal.Length 0 -#> 189 54 Petal.Width 1 -#> 190 54 Sepal.Length 3 -#> 191 54 Sepal.Width 3 -#> 192 55 Petal.Length 0 -#> 193 55 Petal.Width 1 -#> 194 55 Sepal.Length 2 -#> 195 56 Petal.Length 0 -#> 196 56 Petal.Width 1 -#> 197 56 Sepal.Length 3 -#> 198 56 Sepal.Width 4 -#> 199 57 Petal.Length 1 -#> 200 57 Petal.Width 1 -#> 201 57 Sepal.Length 0 -#> 202 57 Sepal.Width 3 -#> 203 58 Petal.Length 1 -#> 204 58 Petal.Width 1 -#> 205 58 Sepal.Length 0 -#> 206 59 Petal.Length 0 -#> 207 59 Petal.Width 1 -#> 208 59 Sepal.Length 4 -#> 209 60 Petal.Length 2 -#> 210 60 Petal.Width 0 -#> 211 60 Sepal.Width 5 -#> 212 61 Petal.Length 1 -#> 213 61 Petal.Width 3 -#> 214 61 Sepal.Length 1 -#> 215 61 Sepal.Width 0 -#> 216 62 Petal.Length 2 -#> 217 62 Petal.Width 0 -#> 218 62 Sepal.Length 3 -#> 219 62 Sepal.Width 3 -#> 220 63 Petal.Length 1 -#> 221 63 Petal.Width 0 -#> 222 63 Sepal.Length 2 -#> 223 63 Sepal.Width 3 -#> 224 64 Petal.Length 3 -#> 225 64 Petal.Width 0 -#> 226 64 Sepal.Length 1 -#> 227 64 Sepal.Width 3 -#> 228 65 Petal.Length 1 -#> 229 65 Petal.Width 1 -#> 230 65 Sepal.Length 0 -#> 231 65 Sepal.Width 3 -#> 232 66 Petal.Length 2 -#> 233 66 Petal.Width 0 -#> 234 66 Sepal.Width 5 -#> 235 67 Petal.Length 0 -#> 236 67 Sepal.Length 2 -#> 237 68 Petal.Length 0 -#> 238 68 Petal.Width 2 -#> 239 68 Sepal.Length 3 -#> 240 69 Petal.Length 0 -#> 241 69 Petal.Width 1 -#> 242 69 Sepal.Length 3 -#> 243 69 Sepal.Width 4 -#> 244 70 Petal.Length 0 -#> 245 70 Petal.Width 2 -#> 246 70 Sepal.Width 4 -#> 247 71 Petal.Length 1 -#> 248 71 Petal.Width 1 -#> 249 71 Sepal.Length 0 -#> 250 72 Petal.Length 1 -#> 251 72 Petal.Width 0 -#> 252 72 Sepal.Length 2 -#> 253 72 Sepal.Width 3 -#> 254 73 Petal.Length 0 -#> 255 73 Petal.Width 1 -#> 256 73 Sepal.Length 2 -#> 257 73 Sepal.Width 4 -#> 258 74 Petal.Length 0 -#> 259 74 Petal.Width 1 -#> 260 74 Sepal.Length 2 -#> 261 75 Petal.Length 1 -#> 262 75 Petal.Width 0 -#> 263 75 Sepal.Length 3 -#> 264 76 Petal.Length 1 -#> 265 76 Petal.Width 0 -#> 266 76 Sepal.Width 4 -#> 267 77 Petal.Length 0 -#> 268 77 Petal.Width 2 -#> 269 77 Sepal.Width 3 -#> 270 78 Petal.Length 3 -#> 271 78 Petal.Width 1 -#> 272 78 Sepal.Length 0 -#> 273 78 Sepal.Width 1 -#> 274 79 Petal.Length 3 -#> 275 79 Petal.Width 0 -#> 276 79 Sepal.Length 1 -#> 277 79 Sepal.Width 4 -#> 278 80 Petal.Length 1 -#> 279 80 Petal.Width 1 -#> 280 80 Sepal.Length 0 -#> 281 80 Sepal.Width 4 -#> 282 81 Petal.Length 2 -#> 283 81 Petal.Width 0 -#> 284 82 Petal.Length 2 -#> 285 82 Petal.Width 0 -#> 286 82 Sepal.Length 4 -#> 287 82 Sepal.Width 3 -#> 288 83 Petal.Length 1 -#> 289 83 Petal.Width 1 -#> 290 83 Sepal.Length 0 -#> 291 84 Petal.Length 2 -#> 292 84 Petal.Width 0 -#> 293 84 Sepal.Width 2 -#> 294 85 Petal.Length 0 -#> 295 85 Petal.Width 2 -#> 296 85 Sepal.Length 2 -#> 297 85 Sepal.Width 3 -#> 298 86 Petal.Length 1 -#> 299 86 Petal.Width 2 -#> 300 86 Sepal.Length 0 -#> 301 86 Sepal.Width 1 -#> 302 87 Petal.Length 0 -#> 303 87 Petal.Width 3 -#> 304 87 Sepal.Width 2 -#> 305 88 Petal.Length 0 -#> 306 88 Petal.Width 3 -#> 307 88 Sepal.Length 2 -#> 308 89 Petal.Length 0 -#> 309 89 Petal.Width 2 -#> 310 89 Sepal.Length 3 -#> 311 89 Sepal.Width 3 -#> 312 90 Petal.Length 1 -#> 313 90 Petal.Width 1 -#> 314 90 Sepal.Length 0 -#> 315 90 Sepal.Width 4 -#> 316 91 Petal.Length 0 -#> 317 91 Petal.Width 4 -#> 318 91 Sepal.Length 3 -#> 319 91 Sepal.Width 3 -#> 320 92 Petal.Length 0 -#> 321 92 Petal.Width 2 -#> 322 92 Sepal.Width 4 -#> 323 93 Petal.Length 0 -#> 324 93 Petal.Width 1 -#> 325 93 Sepal.Length 2 -#> 326 94 Petal.Length 0 -#> 327 94 Petal.Width 3 -#> 328 94 Sepal.Length 1 -#> 329 94 Sepal.Width 4 -#> 330 95 Petal.Length 2 -#> 331 95 Petal.Width 0 -#> 332 96 Petal.Length 1 -#> 333 96 Petal.Width 0 -#> 334 96 Sepal.Length 2 -#> 335 96 Sepal.Width 3 -#> 336 97 Petal.Length 1 -#> 337 97 Petal.Width 0 -#> 338 97 Sepal.Length 3 -#> 339 97 Sepal.Width 2 -#> 340 98 Petal.Length 0 -#> 341 98 Petal.Width 1 -#> 342 98 Sepal.Width 2 -#> 343 99 Petal.Length 3 -#> 344 99 Petal.Width 1 -#> 345 99 Sepal.Length 0 -#> 346 100 Petal.Length 1 -#> 347 100 Petal.Width 0 -#> 348 100 Sepal.Length 1 -#> 349 100 Sepal.Width 2
min_depth_distribution(ranger::ranger(Species ~ ., data = iris, num.trees = 100)) -
#> tree variable minimal_depth -#> 1 1 Petal.Length 0 -#> 2 1 Petal.Width 2 -#> 3 1 Sepal.Length 2 -#> 4 2 Petal.Length 2 -#> 5 2 Petal.Width 0 -#> 6 2 Sepal.Length 4 -#> 7 2 Sepal.Width 3 -#> 8 3 Petal.Length 1 -#> 9 3 Petal.Width 0 -#> 10 3 Sepal.Length 2 -#> 11 3 Sepal.Width 3 -#> 12 4 Petal.Length 2 -#> 13 4 Petal.Width 0 -#> 14 4 Sepal.Length 1 -#> 15 4 Sepal.Width 3 -#> 16 5 Petal.Width 0 -#> 17 5 Sepal.Length 3 -#> 18 6 Petal.Length 1 -#> 19 6 Petal.Width 0 -#> 20 6 Sepal.Length 2 -#> 21 6 Sepal.Width 3 -#> 22 7 Petal.Length 0 -#> 23 7 Petal.Width 2 -#> 24 7 Sepal.Length 1 -#> 25 7 Sepal.Width 2 -#> 26 8 Petal.Length 1 -#> 27 8 Petal.Width 1 -#> 28 8 Sepal.Length 0 -#> 29 8 Sepal.Width 2 -#> 30 9 Petal.Length 0 -#> 31 9 Petal.Width 1 -#> 32 9 Sepal.Length 3 -#> 33 9 Sepal.Width 2 -#> 34 10 Petal.Length 2 -#> 35 10 Petal.Width 1 -#> 36 10 Sepal.Length 0 -#> 37 11 Petal.Length 3 -#> 38 11 Petal.Width 1 -#> 39 11 Sepal.Length 0 -#> 40 11 Sepal.Width 3 -#> 41 12 Petal.Length 1 -#> 42 12 Petal.Width 0 -#> 43 12 Sepal.Width 3 -#> 44 13 Petal.Length 2 -#> 45 13 Petal.Width 3 -#> 46 13 Sepal.Length 0 -#> 47 13 Sepal.Width 1 -#> 48 14 Petal.Length 0 -#> 49 14 Petal.Width 3 -#> 50 14 Sepal.Length 2 -#> 51 14 Sepal.Width 2 -#> 52 15 Petal.Length 2 -#> 53 15 Petal.Width 0 -#> 54 15 Sepal.Length 3 -#> 55 15 Sepal.Width 2 -#> 56 16 Petal.Length 0 -#> 57 16 Petal.Width 3 -#> 58 16 Sepal.Length 4 -#> 59 16 Sepal.Width 4 -#> 60 17 Petal.Length 2 -#> 61 17 Petal.Width 1 -#> 62 17 Sepal.Length 0 -#> 63 17 Sepal.Width 2 -#> 64 18 Petal.Length 2 -#> 65 18 Petal.Width 0 -#> 66 18 Sepal.Length 1 -#> 67 18 Sepal.Width 4 -#> 68 19 Petal.Length 1 -#> 69 19 Petal.Width 0 -#> 70 19 Sepal.Length 2 -#> 71 19 Sepal.Width 2 -#> 72 20 Petal.Length 0 -#> 73 20 Petal.Width 1 -#> 74 20 Sepal.Length 2 -#> 75 20 Sepal.Width 3 -#> 76 21 Petal.Length 2 -#> 77 21 Petal.Width 1 -#> 78 21 Sepal.Length 0 -#> 79 21 Sepal.Width 3 -#> 80 22 Petal.Length 0 -#> 81 22 Petal.Width 2 -#> 82 22 Sepal.Length 3 -#> 83 23 Petal.Length 1 -#> 84 23 Petal.Width 0 -#> 85 23 Sepal.Width 4 -#> 86 24 Petal.Length 2 -#> 87 24 Petal.Width 0 -#> 88 24 Sepal.Width 3 -#> 89 25 Petal.Length 0 -#> 90 25 Petal.Width 2 -#> 91 25 Sepal.Length 1 -#> 92 26 Petal.Length 1 -#> 93 26 Petal.Width 0 -#> 94 26 Sepal.Length 2 -#> 95 26 Sepal.Width 3 -#> 96 27 Petal.Length 1 -#> 97 27 Petal.Width 0 -#> 98 27 Sepal.Length 2 -#> 99 27 Sepal.Width 3 -#> 100 28 Petal.Length 1 -#> 101 28 Petal.Width 0 -#> 102 28 Sepal.Length 4 -#> 103 28 Sepal.Width 3 -#> 104 29 Petal.Length 0 -#> 105 30 Petal.Length 2 -#> 106 30 Petal.Width 0 -#> 107 31 Petal.Length 0 -#> 108 31 Petal.Width 1 -#> 109 31 Sepal.Length 4 -#> 110 31 Sepal.Width 2 -#> 111 32 Petal.Length 3 -#> 112 32 Petal.Width 0 -#> 113 32 Sepal.Length 1 -#> 114 32 Sepal.Width 3 -#> 115 33 Petal.Length 1 -#> 116 33 Petal.Width 1 -#> 117 33 Sepal.Length 0 -#> 118 33 Sepal.Width 5 -#> 119 34 Petal.Length 1 -#> 120 34 Petal.Width 1 -#> 121 34 Sepal.Length 0 -#> 122 34 Sepal.Width 3 -#> 123 35 Petal.Length 0 -#> 124 35 Petal.Width 1 -#> 125 35 Sepal.Width 3 -#> 126 36 Petal.Length 0 -#> 127 36 Petal.Width 1 -#> 128 36 Sepal.Width 3 -#> 129 37 Petal.Length 2 -#> 130 37 Petal.Width 0 -#> 131 37 Sepal.Length 1 -#> 132 37 Sepal.Width 3 -#> 133 38 Petal.Length 0 -#> 134 38 Petal.Width 1 -#> 135 38 Sepal.Width 2 -#> 136 39 Petal.Length 0 -#> 137 39 Petal.Width 2 -#> 138 40 Petal.Length 3 -#> 139 40 Petal.Width 0 -#> 140 40 Sepal.Length 1 -#> 141 41 Petal.Length 2 -#> 142 41 Petal.Width 0 -#> 143 41 Sepal.Length 1 -#> 144 42 Petal.Length 0 -#> 145 42 Petal.Width 1 -#> 146 42 Sepal.Length 3 -#> 147 43 Petal.Length 1 -#> 148 43 Petal.Width 0 -#> 149 43 Sepal.Length 2 -#> 150 44 Petal.Length 0 -#> 151 44 Petal.Width 2 -#> 152 44 Sepal.Width 4 -#> 153 45 Petal.Length 0 -#> 154 45 Petal.Width 2 -#> 155 45 Sepal.Width 3 -#> 156 46 Petal.Length 1 -#> 157 46 Petal.Width 2 -#> 158 46 Sepal.Length 0 -#> 159 46 Sepal.Width 1 -#> 160 47 Petal.Length 1 -#> 161 47 Petal.Width 0 -#> 162 47 Sepal.Length 4 -#> 163 47 Sepal.Width 2 -#> 164 48 Petal.Length 0 -#> 165 48 Petal.Width 2 -#> 166 48 Sepal.Width 4 -#> 167 49 Petal.Width 0 -#> 168 49 Sepal.Length 3 -#> 169 49 Sepal.Width 2 -#> 170 50 Petal.Length 1 -#> 171 50 Petal.Width 3 -#> 172 50 Sepal.Length 0 -#> 173 50 Sepal.Width 2 -#> 174 51 Petal.Length 0 -#> 175 51 Petal.Width 1 -#> 176 52 Petal.Length 0 -#> 177 52 Petal.Width 2 -#> 178 52 Sepal.Length 3 -#> 179 53 Petal.Length 0 -#> 180 53 Petal.Width 1 -#> 181 54 Petal.Length 0 -#> 182 54 Petal.Width 1 -#> 183 54 Sepal.Length 3 -#> 184 55 Petal.Length 0 -#> 185 55 Petal.Width 2 -#> 186 56 Petal.Length 0 -#> 187 56 Petal.Width 2 -#> 188 56 Sepal.Length 4 -#> 189 56 Sepal.Width 3 -#> 190 57 Petal.Length 0 -#> 191 57 Petal.Width 2 -#> 192 58 Petal.Length 0 -#> 193 58 Petal.Width 1 -#> 194 58 Sepal.Length 2 -#> 195 58 Sepal.Width 4 -#> 196 59 Petal.Length 2 -#> 197 59 Petal.Width 0 -#> 198 59 Sepal.Width 3 -#> 199 60 Petal.Length 0 -#> 200 60 Petal.Width 2 -#> 201 60 Sepal.Length 2 -#> 202 60 Sepal.Width 5 -#> 203 61 Petal.Length 1 -#> 204 61 Petal.Width 1 -#> 205 61 Sepal.Length 0 -#> 206 61 Sepal.Width 2 -#> 207 62 Petal.Length 3 -#> 208 62 Petal.Width 0 -#> 209 62 Sepal.Length 2 -#> 210 62 Sepal.Width 2 -#> 211 63 Petal.Length 1 -#> 212 63 Petal.Width 0 -#> 213 63 Sepal.Length 4 -#> 214 63 Sepal.Width 3 -#> 215 64 Petal.Length 0 -#> 216 64 Petal.Width 2 -#> 217 64 Sepal.Length 1 -#> 218 64 Sepal.Width 2 -#> 219 65 Petal.Length 2 -#> 220 65 Petal.Width 1 -#> 221 65 Sepal.Length 0 -#> 222 66 Petal.Length 1 -#> 223 66 Petal.Width 0 -#> 224 66 Sepal.Length 4 -#> 225 66 Sepal.Width 2 -#> 226 67 Petal.Length 0 -#> 227 67 Petal.Width 2 -#> 228 67 Sepal.Length 4 -#> 229 68 Petal.Length 2 -#> 230 68 Petal.Width 2 -#> 231 68 Sepal.Length 0 -#> 232 68 Sepal.Width 1 -#> 233 69 Petal.Length 1 -#> 234 69 Petal.Width 2 -#> 235 69 Sepal.Length 0 -#> 236 69 Sepal.Width 2 -#> 237 70 Petal.Length 0 -#> 238 70 Petal.Width 2 -#> 239 70 Sepal.Length 3 -#> 240 71 Petal.Length 1 -#> 241 71 Petal.Width 1 -#> 242 71 Sepal.Length 0 -#> 243 72 Petal.Length 3 -#> 244 72 Petal.Width 0 -#> 245 72 Sepal.Length 2 -#> 246 73 Petal.Length 1 -#> 247 73 Petal.Width 2 -#> 248 73 Sepal.Length 0 -#> 249 74 Petal.Length 2 -#> 250 74 Petal.Width 0 -#> 251 74 Sepal.Length 4 -#> 252 74 Sepal.Width 3 -#> 253 75 Petal.Length 2 -#> 254 75 Petal.Width 0 -#> 255 75 Sepal.Length 4 -#> 256 76 Petal.Length 3 -#> 257 76 Petal.Width 0 -#> 258 76 Sepal.Length 1 -#> 259 76 Sepal.Width 3 -#> 260 77 Petal.Length 1 -#> 261 77 Petal.Width 1 -#> 262 77 Sepal.Length 0 -#> 263 78 Petal.Length 2 -#> 264 78 Petal.Width 0 -#> 265 78 Sepal.Width 2 -#> 266 79 Petal.Length 2 -#> 267 79 Petal.Width 0 -#> 268 79 Sepal.Length 1 -#> 269 79 Sepal.Width 3 -#> 270 80 Petal.Length 2 -#> 271 80 Petal.Width 0 -#> 272 80 Sepal.Length 2 -#> 273 80 Sepal.Width 3 -#> 274 81 Petal.Length 2 -#> 275 81 Petal.Width 0 -#> 276 81 Sepal.Length 3 -#> 277 81 Sepal.Width 2 -#> 278 82 Petal.Length 0 -#> 279 82 Petal.Width 2 -#> 280 82 Sepal.Length 1 -#> 281 82 Sepal.Width 3 -#> 282 83 Petal.Length 0 -#> 283 83 Petal.Width 2 -#> 284 83 Sepal.Length 2 -#> 285 83 Sepal.Width 3 -#> 286 84 Petal.Length 0 -#> 287 84 Petal.Width 2 -#> 288 84 Sepal.Length 2 -#> 289 84 Sepal.Width 4 -#> 290 85 Petal.Length 2 -#> 291 85 Petal.Width 0 -#> 292 86 Petal.Length 2 -#> 293 86 Petal.Width 0 -#> 294 87 Petal.Length 0 -#> 295 87 Petal.Width 4 -#> 296 87 Sepal.Width 2 -#> 297 88 Petal.Width 0 -#> 298 88 Sepal.Length 2 -#> 299 88 Sepal.Width 3 -#> 300 89 Petal.Length 2 -#> 301 89 Petal.Width 0 -#> 302 89 Sepal.Length 3 -#> 303 89 Sepal.Width 3 -#> 304 90 Petal.Length 1 -#> 305 90 Petal.Width 0 -#> 306 90 Sepal.Length 3 -#> 307 90 Sepal.Width 3 -#> 308 91 Petal.Length 0 -#> 309 91 Petal.Width 3 -#> 310 91 Sepal.Length 2 -#> 311 92 Petal.Length 0 -#> 312 92 Petal.Width 1 -#> 313 92 Sepal.Width 2 -#> 314 93 Petal.Length 0 -#> 315 93 Petal.Width 2 -#> 316 94 Petal.Length 1 -#> 317 94 Petal.Width 0 -#> 318 94 Sepal.Length 3 -#> 319 95 Petal.Length 1 -#> 320 95 Petal.Width 4 -#> 321 95 Sepal.Length 0 -#> 322 95 Sepal.Width 2 -#> 323 96 Petal.Length 1 -#> 324 96 Sepal.Length 0 -#> 325 96 Sepal.Width 2 -#> 326 97 Petal.Length 3 -#> 327 97 Petal.Width 0 -#> 328 97 Sepal.Length 2 -#> 329 98 Petal.Length 1 -#> 330 98 Petal.Width 0 -#> 331 98 Sepal.Width 3 -#> 332 99 Petal.Length 1 -#> 333 99 Petal.Width 0 -#> 334 99 Sepal.Width 3 -#> 335 100 Petal.Length 1 -#> 336 100 Petal.Width 3 -#> 337 100 Sepal.Length 0 -#> 338 100 Sepal.Width 4
-
+
+

Examples

+
min_depth_distribution(randomForest::randomForest(Species ~ ., data = iris, ntree = 100))
+#>     tree     variable minimal_depth
+#> 1      1 Petal.Length             0
+#> 2      1  Petal.Width             2
+#> 3      1 Sepal.Length             2
+#> 4      2 Petal.Length             2
+#> 5      2  Petal.Width             1
+#> 6      2 Sepal.Length             0
+#> 7      2  Sepal.Width             2
+#> 8      3 Petal.Length             3
+#> 9      3  Petal.Width             1
+#> 10     3 Sepal.Length             0
+#> 11     3  Sepal.Width             2
+#> 12     4 Petal.Length             0
+#> 13     4  Petal.Width             2
+#> 14     4 Sepal.Length             3
+#> 15     5 Petal.Length             0
+#> 16     5  Petal.Width             2
+#> 17     5 Sepal.Length             2
+#> 18     5  Sepal.Width             3
+#> 19     6 Petal.Length             0
+#> 20     6  Petal.Width             2
+#> 21     7 Petal.Length             2
+#> 22     7  Petal.Width             0
+#> 23     7 Sepal.Length             4
+#> 24     7  Sepal.Width             3
+#> 25     8 Petal.Length             0
+#> 26     8  Petal.Width             4
+#> 27     8 Sepal.Length             4
+#> 28     8  Sepal.Width             2
+#> 29     9 Petal.Length             3
+#> 30     9  Petal.Width             0
+#> 31     9 Sepal.Length             2
+#> 32     9  Sepal.Width             3
+#> 33    10 Petal.Length             2
+#> 34    10  Petal.Width             0
+#> 35    10 Sepal.Length             1
+#> 36    10  Sepal.Width             2
+#> 37    11 Petal.Length             1
+#> 38    11  Petal.Width             1
+#> 39    11 Sepal.Length             0
+#> 40    11  Sepal.Width             5
+#> 41    12 Petal.Length             5
+#> 42    12  Petal.Width             0
+#> 43    12 Sepal.Length             2
+#> 44    12  Sepal.Width             4
+#> 45    13 Petal.Length             0
+#> 46    13  Petal.Width             2
+#> 47    14 Petal.Length             2
+#> 48    14  Petal.Width             0
+#> 49    14 Sepal.Length             2
+#> 50    15 Petal.Length             4
+#> 51    15  Petal.Width             0
+#> 52    15 Sepal.Length             2
+#> 53    16 Petal.Length             0
+#> 54    16  Petal.Width             1
+#> 55    16 Sepal.Length             2
+#> 56    17 Petal.Length             2
+#> 57    17  Petal.Width             0
+#> 58    17 Sepal.Length             2
+#> 59    18 Petal.Length             0
+#> 60    18  Petal.Width             2
+#> 61    18 Sepal.Length             4
+#> 62    18  Sepal.Width             3
+#> 63    19 Petal.Length             1
+#> 64    19  Petal.Width             0
+#> 65    19 Sepal.Length             2
+#> 66    19  Sepal.Width             4
+#> 67    20 Petal.Length             1
+#> 68    20  Petal.Width             0
+#> 69    20 Sepal.Length             4
+#> 70    20  Sepal.Width             3
+#> 71    21 Petal.Length             2
+#> 72    21  Petal.Width             0
+#> 73    21  Sepal.Width             3
+#> 74    22 Petal.Length             3
+#> 75    22  Petal.Width             0
+#> 76    22 Sepal.Length             2
+#> 77    23  Petal.Width             0
+#> 78    23  Sepal.Width             2
+#> 79    24 Petal.Length             2
+#> 80    24  Petal.Width             0
+#> 81    24  Sepal.Width             3
+#> 82    25 Petal.Length             0
+#> 83    25  Petal.Width             1
+#> 84    26 Petal.Length             0
+#> 85    26  Petal.Width             2
+#> 86    26 Sepal.Length             2
+#> 87    27 Petal.Length             0
+#> 88    27  Petal.Width             2
+#> 89    27 Sepal.Length             2
+#> 90    28 Petal.Length             0
+#> 91    28  Petal.Width             1
+#> 92    28 Sepal.Length             2
+#> 93    28  Sepal.Width             3
+#> 94    29 Petal.Length             2
+#> 95    29  Petal.Width             0
+#> 96    30 Petal.Length             0
+#> 97    30  Petal.Width             3
+#> 98    30 Sepal.Length             1
+#> 99    30  Sepal.Width             3
+#> 100   31 Petal.Length             0
+#> 101   31  Petal.Width             1
+#> 102   31  Sepal.Width             3
+#> 103   32 Petal.Length             3
+#> 104   32  Petal.Width             0
+#> 105   32 Sepal.Length             2
+#> 106   32  Sepal.Width             4
+#> 107   33 Petal.Length             0
+#> 108   33  Petal.Width             1
+#> 109   33 Sepal.Length             2
+#> 110   33  Sepal.Width             3
+#> 111   34 Petal.Length             2
+#> 112   34  Petal.Width             0
+#> 113   34 Sepal.Length             1
+#> 114   35 Petal.Length             0
+#> 115   35  Petal.Width             1
+#> 116   35  Sepal.Width             3
+#> 117   36 Petal.Length             0
+#> 118   36  Petal.Width             1
+#> 119   36 Sepal.Length             2
+#> 120   36  Sepal.Width             3
+#> 121   37 Petal.Length             3
+#> 122   37  Petal.Width             0
+#> 123   37 Sepal.Length             3
+#> 124   37  Sepal.Width             1
+#> 125   38 Petal.Length             3
+#> 126   38  Petal.Width             0
+#> 127   38 Sepal.Length             1
+#> 128   38  Sepal.Width             2
+#> 129   39 Petal.Length             1
+#> 130   39  Petal.Width             1
+#> 131   39 Sepal.Length             0
+#> 132   40 Petal.Length             1
+#> 133   40  Petal.Width             0
+#> 134   40 Sepal.Length             2
+#> 135   40  Sepal.Width             2
+#> 136   41 Petal.Length             2
+#> 137   41  Petal.Width             3
+#> 138   41 Sepal.Length             0
+#> 139   41  Sepal.Width             1
+#> 140   42 Petal.Length             1
+#> 141   42  Petal.Width             0
+#> 142   43 Petal.Length             2
+#> 143   43  Petal.Width             0
+#> 144   43 Sepal.Length             3
+#> 145   43  Sepal.Width             2
+#> 146   44 Petal.Length             2
+#> 147   44  Petal.Width             0
+#> 148   44 Sepal.Length             2
+#> 149   44  Sepal.Width             3
+#> 150   45 Petal.Length             1
+#> 151   45  Petal.Width             0
+#> 152   46 Petal.Length             0
+#> 153   46  Petal.Width             1
+#> 154   46 Sepal.Length             2
+#> 155   46  Sepal.Width             3
+#> 156   47 Petal.Length             2
+#> 157   47  Petal.Width             1
+#> 158   47 Sepal.Length             0
+#> 159   47  Sepal.Width             1
+#> 160   48 Petal.Length             0
+#> 161   48  Petal.Width             1
+#> 162   48  Sepal.Width             3
+#> 163   49 Petal.Length             0
+#> 164   49  Petal.Width             1
+#> 165   49 Sepal.Length             3
+#> 166   49  Sepal.Width             4
+#> 167   50 Petal.Length             3
+#> 168   50  Petal.Width             0
+#> 169   50 Sepal.Length             2
+#> 170   50  Sepal.Width             2
+#> 171   51 Petal.Length             1
+#> 172   51  Petal.Width             0
+#> 173   51 Sepal.Length             3
+#> 174   51  Sepal.Width             2
+#> 175   52 Petal.Length             1
+#> 176   52  Petal.Width             1
+#> 177   52 Sepal.Length             0
+#> 178   52  Sepal.Width             4
+#> 179   53 Petal.Length             0
+#> 180   53  Petal.Width             2
+#> 181   53 Sepal.Length             1
+#> 182   54 Petal.Length             0
+#> 183   54  Petal.Width             1
+#> 184   54 Sepal.Length             2
+#> 185   54  Sepal.Width             2
+#> 186   55 Petal.Length             0
+#> 187   55  Petal.Width             2
+#> 188   55 Sepal.Length             1
+#> 189   56 Petal.Length             0
+#> 190   56  Petal.Width             3
+#> 191   56 Sepal.Length             2
+#> 192   56  Sepal.Width             5
+#> 193   57 Petal.Length             1
+#> 194   57  Petal.Width             1
+#> 195   57 Sepal.Length             0
+#> 196   57  Sepal.Width             2
+#> 197   58 Petal.Length             1
+#> 198   58  Petal.Width             1
+#> 199   58 Sepal.Length             0
+#> 200   58  Sepal.Width             2
+#> 201   59 Petal.Length             0
+#> 202   59  Petal.Width             1
+#> 203   59 Sepal.Length             3
+#> 204   59  Sepal.Width             4
+#> 205   60 Petal.Length             2
+#> 206   60  Petal.Width             0
+#> 207   60 Sepal.Length             2
+#> 208   60  Sepal.Width             3
+#> 209   61 Petal.Length             0
+#> 210   61  Petal.Width             3
+#> 211   61 Sepal.Length             1
+#> 212   62 Petal.Length             1
+#> 213   62  Petal.Width             2
+#> 214   62 Sepal.Length             0
+#> 215   62  Sepal.Width             1
+#> 216   63 Petal.Length             3
+#> 217   63  Petal.Width             0
+#> 218   63 Sepal.Length             3
+#> 219   63  Sepal.Width             2
+#> 220   64 Petal.Length             0
+#> 221   64  Petal.Width             1
+#> 222   64 Sepal.Length             2
+#> 223   64  Sepal.Width             3
+#> 224   65 Petal.Length             1
+#> 225   65  Petal.Width             0
+#> 226   65  Sepal.Width             4
+#> 227   66 Petal.Length             1
+#> 228   66  Petal.Width             0
+#> 229   66 Sepal.Length             2
+#> 230   67 Petal.Length             0
+#> 231   67  Petal.Width             1
+#> 232   68 Petal.Length             0
+#> 233   68  Petal.Width             1
+#> 234   68 Sepal.Length             2
+#> 235   69 Petal.Length             1
+#> 236   69  Petal.Width             2
+#> 237   69 Sepal.Length             0
+#> 238   69  Sepal.Width             1
+#> 239   70 Petal.Length             2
+#> 240   70  Petal.Width             0
+#> 241   70 Sepal.Length             1
+#> 242   71 Petal.Length             1
+#> 243   71  Petal.Width             2
+#> 244   71 Sepal.Length             0
+#> 245   71  Sepal.Width             2
+#> 246   72 Petal.Length             1
+#> 247   72  Petal.Width             0
+#> 248   72 Sepal.Length             3
+#> 249   73 Petal.Length             2
+#> 250   73  Petal.Width             0
+#> 251   73 Sepal.Length             1
+#> 252   73  Sepal.Width             3
+#> 253   74 Petal.Length             1
+#> 254   74  Petal.Width             0
+#> 255   74 Sepal.Length             3
+#> 256   75 Petal.Length             0
+#> 257   75  Petal.Width             2
+#> 258   75 Sepal.Length             3
+#> 259   75  Sepal.Width             3
+#> 260   76 Petal.Length             0
+#> 261   76  Petal.Width             1
+#> 262   76 Sepal.Length             3
+#> 263   77 Petal.Length             0
+#> 264   77  Petal.Width             2
+#> 265   77  Sepal.Width             3
+#> 266   78 Petal.Length             0
+#> 267   78  Petal.Width             2
+#> 268   78  Sepal.Width             3
+#> 269   79 Petal.Length             1
+#> 270   79  Petal.Width             2
+#> 271   79 Sepal.Length             0
+#> 272   79  Sepal.Width             1
+#> 273   80 Petal.Length             0
+#> 274   80  Petal.Width             3
+#> 275   80 Sepal.Length             1
+#> 276   80  Sepal.Width             5
+#> 277   81 Petal.Length             1
+#> 278   81  Petal.Width             2
+#> 279   81 Sepal.Length             0
+#> 280   81  Sepal.Width             2
+#> 281   82 Petal.Length             3
+#> 282   82  Petal.Width             1
+#> 283   82 Sepal.Length             0
+#> 284   82  Sepal.Width             1
+#> 285   83 Petal.Length             1
+#> 286   83  Petal.Width             0
+#> 287   83 Sepal.Length             3
+#> 288   83  Sepal.Width             4
+#> 289   84 Petal.Length             0
+#> 290   84  Petal.Width             2
+#> 291   84 Sepal.Length             1
+#> 292   84  Sepal.Width             5
+#> 293   85 Petal.Length             1
+#> 294   85  Petal.Width             1
+#> 295   85 Sepal.Length             0
+#> 296   86 Petal.Length             0
+#> 297   86  Petal.Width             4
+#> 298   86 Sepal.Length             2
+#> 299   86  Sepal.Width             1
+#> 300   87 Petal.Length             0
+#> 301   87  Petal.Width             2
+#> 302   87 Sepal.Length             4
+#> 303   87  Sepal.Width             3
+#> 304   88 Petal.Length             1
+#> 305   88  Petal.Width             1
+#> 306   88 Sepal.Length             0
+#> 307   88  Sepal.Width             2
+#> 308   89 Petal.Length             0
+#> 309   89  Petal.Width             1
+#> 310   89 Sepal.Length             4
+#> 311   89  Sepal.Width             3
+#> 312   90 Petal.Length             0
+#> 313   90  Petal.Width             1
+#> 314   90 Sepal.Length             2
+#> 315   90  Sepal.Width             3
+#> 316   91 Petal.Length             0
+#> 317   91  Petal.Width             2
+#> 318   91  Sepal.Width             3
+#> 319   92 Petal.Length             0
+#> 320   92  Petal.Width             5
+#> 321   92 Sepal.Length             2
+#> 322   92  Sepal.Width             3
+#> 323   93 Petal.Length             2
+#> 324   93  Petal.Width             0
+#> 325   94 Petal.Length             0
+#> 326   94  Petal.Width             2
+#> 327   94 Sepal.Length             3
+#> 328   94  Sepal.Width             4
+#> 329   95 Petal.Length             0
+#> 330   95  Petal.Width             1
+#> 331   95 Sepal.Length             2
+#> 332   96 Petal.Length             3
+#> 333   96  Petal.Width             0
+#>  [ reached 'max' / getOption("max.print") -- omitted 16 rows ]
+min_depth_distribution(ranger::ranger(Species ~ ., data = iris, num.trees = 100))
+#>     tree     variable minimal_depth
+#> 1      1 Petal.Length             0
+#> 2      1  Petal.Width             5
+#> 3      1 Sepal.Length             3
+#> 4      1  Sepal.Width             4
+#> 5      2 Petal.Length             1
+#> 6      2  Petal.Width             1
+#> 7      2 Sepal.Length             0
+#> 8      2  Sepal.Width             4
+#> 9      3 Petal.Length             2
+#> 10     3  Petal.Width             0
+#> 11     3 Sepal.Length             7
+#> 12     3  Sepal.Width             2
+#> 13     4 Petal.Length             1
+#> 14     4  Petal.Width             1
+#> 15     4 Sepal.Length             0
+#> 16     4  Sepal.Width             4
+#> 17     5 Petal.Length             0
+#> 18     5  Petal.Width             1
+#> 19     5 Sepal.Length             2
+#> 20     5  Sepal.Width             5
+#> 21     6 Petal.Length             2
+#> 22     6  Petal.Width             1
+#> 23     6 Sepal.Length             0
+#> 24     6  Sepal.Width             1
+#> 25     7 Petal.Length             0
+#> 26     7  Petal.Width             1
+#> 27     7 Sepal.Length             4
+#> 28     7  Sepal.Width             3
+#> 29     8 Petal.Length             1
+#> 30     8  Petal.Width             0
+#> 31     8 Sepal.Length             2
+#> 32     8  Sepal.Width             3
+#> 33     9 Petal.Length             0
+#> 34     9  Petal.Width             1
+#> 35    10 Petal.Length             0
+#> 36    10  Petal.Width             1
+#> 37    10  Sepal.Width             3
+#> 38    11 Petal.Length             1
+#> 39    11  Petal.Width             0
+#> 40    11  Sepal.Width             3
+#> 41    12 Petal.Length             3
+#> 42    12  Petal.Width             1
+#> 43    12 Sepal.Length             0
+#> 44    12  Sepal.Width             2
+#> 45    13 Petal.Length             5
+#> 46    13  Petal.Width             0
+#> 47    13 Sepal.Length             1
+#> 48    13  Sepal.Width             3
+#> 49    14 Petal.Length             1
+#> 50    14  Petal.Width             0
+#> 51    14 Sepal.Length             2
+#> 52    15 Petal.Length             0
+#> 53    15  Petal.Width             1
+#> 54    15 Sepal.Length             2
+#> 55    16 Petal.Length             2
+#> 56    16  Petal.Width             0
+#> 57    16 Sepal.Length             2
+#> 58    17 Petal.Length             1
+#> 59    17  Petal.Width             3
+#> 60    17 Sepal.Length             0
+#> 61    17  Sepal.Width             2
+#> 62    18 Petal.Length             0
+#> 63    18  Petal.Width             2
+#> 64    18 Sepal.Length             1
+#> 65    18  Sepal.Width             4
+#> 66    19 Petal.Length             0
+#> 67    19  Petal.Width             1
+#> 68    19  Sepal.Width             3
+#> 69    20 Petal.Length             0
+#> 70    20  Petal.Width             2
+#> 71    20 Sepal.Length             3
+#> 72    21 Petal.Length             0
+#> 73    21  Petal.Width             1
+#> 74    21 Sepal.Length             3
+#> 75    21  Sepal.Width             3
+#> 76    22 Petal.Length             0
+#> 77    22  Petal.Width             2
+#> 78    22 Sepal.Length             3
+#> 79    22  Sepal.Width             2
+#> 80    23 Petal.Length             1
+#> 81    23  Petal.Width             0
+#> 82    23 Sepal.Length             3
+#> 83    23  Sepal.Width             3
+#> 84    24 Petal.Length             1
+#> 85    24  Petal.Width             2
+#> 86    24 Sepal.Length             0
+#> 87    24  Sepal.Width             1
+#> 88    25 Petal.Length             1
+#> 89    25  Petal.Width             1
+#> 90    25 Sepal.Length             0
+#> 91    26 Petal.Length             0
+#> 92    26  Petal.Width             1
+#> 93    26 Sepal.Length             4
+#> 94    27 Petal.Length             0
+#> 95    27  Petal.Width             2
+#> 96    27 Sepal.Length             3
+#> 97    27  Sepal.Width             3
+#> 98    28 Petal.Length             0
+#> 99    28  Petal.Width             1
+#> 100   28 Sepal.Length             2
+#> 101   28  Sepal.Width             2
+#> 102   29 Petal.Length             1
+#> 103   29  Petal.Width             0
+#> 104   30 Petal.Length             1
+#> 105   30  Petal.Width             0
+#> 106   30 Sepal.Length             3
+#> 107   31 Petal.Length             0
+#> 108   31  Petal.Width             1
+#> 109   31 Sepal.Length             2
+#> 110   32 Petal.Length             1
+#> 111   32  Petal.Width             0
+#> 112   32 Sepal.Length             3
+#> 113   33 Petal.Length             0
+#> 114   33  Petal.Width             1
+#> 115   33 Sepal.Length             3
+#> 116   33  Sepal.Width             3
+#> 117   34 Petal.Length             0
+#> 118   34  Petal.Width             1
+#> 119   34 Sepal.Length             2
+#> 120   34  Sepal.Width             3
+#> 121   35 Petal.Length             3
+#> 122   35  Petal.Width             0
+#> 123   35 Sepal.Length             2
+#> 124   36 Petal.Length             2
+#> 125   36  Petal.Width             0
+#> 126   36 Sepal.Length             2
+#> 127   36  Sepal.Width             3
+#> 128   37 Petal.Length             1
+#> 129   37  Petal.Width             3
+#> 130   37 Sepal.Length             0
+#> 131   37  Sepal.Width             1
+#> 132   38 Petal.Length             1
+#> 133   38  Petal.Width             0
+#> 134   38 Sepal.Length             3
+#> 135   38  Sepal.Width             4
+#> 136   39 Petal.Length             1
+#> 137   39  Petal.Width             0
+#> 138   39 Sepal.Length             4
+#> 139   39  Sepal.Width             3
+#> 140   40 Petal.Length             0
+#> 141   40  Petal.Width             1
+#> 142   40 Sepal.Length             3
+#> 143   40  Sepal.Width             3
+#> 144   41 Petal.Length             1
+#> 145   41  Petal.Width             0
+#> 146   41 Sepal.Length             3
+#> 147   41  Sepal.Width             3
+#> 148   42 Petal.Length             0
+#> 149   42  Petal.Width             2
+#> 150   42 Sepal.Length             1
+#> 151   42  Sepal.Width             3
+#> 152   43 Petal.Length             0
+#> 153   43  Petal.Width             2
+#> 154   43 Sepal.Length             2
+#> 155   43  Sepal.Width             4
+#> 156   44 Petal.Length             1
+#> 157   44  Petal.Width             0
+#> 158   44 Sepal.Length             2
+#> 159   44  Sepal.Width             3
+#> 160   45 Petal.Length             0
+#> 161   45  Petal.Width             2
+#> 162   45 Sepal.Length             3
+#> 163   45  Sepal.Width             4
+#> 164   46 Petal.Length             2
+#> 165   46  Petal.Width             0
+#> 166   46 Sepal.Length             1
+#> 167   46  Sepal.Width             3
+#> 168   47 Petal.Length             2
+#> 169   47  Petal.Width             0
+#> 170   47 Sepal.Length             2
+#> 171   47  Sepal.Width             4
+#> 172   48 Petal.Length             0
+#> 173   48  Petal.Width             2
+#> 174   49 Petal.Length             1
+#> 175   49  Petal.Width             0
+#> 176   49 Sepal.Length             3
+#> 177   49  Sepal.Width             4
+#> 178   50 Petal.Length             4
+#> 179   50  Petal.Width             0
+#> 180   50 Sepal.Length             2
+#> 181   50  Sepal.Width             2
+#> 182   51 Petal.Length             1
+#> 183   51  Petal.Width             2
+#> 184   51 Sepal.Length             0
+#> 185   52 Petal.Length             1
+#> 186   52  Petal.Width             0
+#> 187   52 Sepal.Length             3
+#> 188   52  Sepal.Width             2
+#> 189   53 Petal.Length             0
+#> 190   53  Petal.Width             1
+#> 191   53 Sepal.Length             2
+#> 192   53  Sepal.Width             3
+#> 193   54 Petal.Length             0
+#> 194   54  Petal.Width             3
+#> 195   54 Sepal.Length             3
+#> 196   54  Sepal.Width             2
+#> 197   55 Petal.Length             0
+#> 198   55  Petal.Width             1
+#> 199   55 Sepal.Length             2
+#> 200   56 Petal.Length             1
+#> 201   56  Petal.Width             1
+#> 202   56 Sepal.Length             0
+#> 203   57 Petal.Length             2
+#> 204   57  Petal.Width             0
+#> 205   57 Sepal.Length             2
+#> 206   57  Sepal.Width             3
+#> 207   58 Petal.Length             2
+#> 208   58  Petal.Width             1
+#> 209   58 Sepal.Length             0
+#> 210   59 Petal.Length             0
+#> 211   59  Petal.Width             1
+#> 212   59 Sepal.Length             2
+#> 213   59  Sepal.Width             4
+#> 214   60 Petal.Length             3
+#> 215   60  Petal.Width             0
+#> 216   60 Sepal.Length             1
+#> 217   60  Sepal.Width             4
+#> 218   61 Petal.Length             0
+#> 219   61  Petal.Width             2
+#> 220   61 Sepal.Length             1
+#> 221   61  Sepal.Width             3
+#> 222   62 Petal.Length             2
+#> 223   62  Petal.Width             0
+#> 224   62 Sepal.Length             1
+#> 225   62  Sepal.Width             3
+#> 226   63 Petal.Length             2
+#> 227   63  Petal.Width             0
+#> 228   63 Sepal.Length             3
+#> 229   63  Sepal.Width             3
+#> 230   64 Petal.Length             1
+#> 231   64  Petal.Width             0
+#> 232   65 Petal.Length             0
+#> 233   65  Petal.Width             2
+#> 234   65 Sepal.Length             2
+#> 235   66 Petal.Length             2
+#> 236   66  Petal.Width             1
+#> 237   66 Sepal.Length             0
+#> 238   66  Sepal.Width             1
+#> 239   67  Petal.Width             0
+#> 240   67 Sepal.Length             1
+#> 241   67  Sepal.Width             4
+#> 242   68 Petal.Length             0
+#> 243   68  Petal.Width             2
+#> 244   68 Sepal.Length             2
+#> 245   68  Sepal.Width             3
+#> 246   69 Petal.Length             3
+#> 247   69  Petal.Width             0
+#> 248   69 Sepal.Length             1
+#> 249   70 Petal.Length             2
+#> 250   70  Petal.Width             0
+#> 251   70  Sepal.Width             4
+#> 252   71 Petal.Length             0
+#> 253   71  Petal.Width             1
+#> 254   71 Sepal.Length             2
+#> 255   71  Sepal.Width             3
+#> 256   72 Petal.Length             2
+#> 257   72  Petal.Width             0
+#> 258   72 Sepal.Length             3
+#> 259   73 Petal.Length             0
+#> 260   73 Sepal.Length             2
+#> 261   73  Sepal.Width             5
+#> 262   74 Petal.Length             2
+#> 263   74  Petal.Width             0
+#> 264   74 Sepal.Length             4
+#> 265   75 Petal.Length             0
+#> 266   75  Petal.Width             1
+#> 267   75 Sepal.Length             2
+#> 268   75  Sepal.Width             2
+#> 269   76 Petal.Length             1
+#> 270   76  Petal.Width             0
+#> 271   76 Sepal.Length             3
+#> 272   76  Sepal.Width             4
+#> 273   77 Petal.Length             2
+#> 274   77  Petal.Width             0
+#> 275   77 Sepal.Length             1
+#> 276   77  Sepal.Width             3
+#> 277   78 Petal.Length             0
+#> 278   78  Petal.Width             1
+#> 279   78 Sepal.Length             2
+#> 280   79 Petal.Length             1
+#> 281   79  Petal.Width             0
+#> 282   79 Sepal.Length             4
+#> 283   79  Sepal.Width             4
+#> 284   80 Petal.Length             0
+#> 285   80  Petal.Width             2
+#> 286   80 Sepal.Length             4
+#> 287   80  Sepal.Width             2
+#> 288   81 Petal.Length             1
+#> 289   81  Petal.Width             0
+#> 290   81 Sepal.Length             2
+#> 291   81  Sepal.Width             4
+#> 292   82 Petal.Length             2
+#> 293   82  Petal.Width             0
+#> 294   82 Sepal.Length             2
+#> 295   82  Sepal.Width             3
+#> 296   83 Petal.Length             1
+#> 297   83  Petal.Width             1
+#> 298   83 Sepal.Length             0
+#> 299   84 Petal.Length             0
+#> 300   84  Petal.Width             4
+#> 301   84 Sepal.Length             2
+#> 302   84  Sepal.Width             5
+#> 303   85 Petal.Length             3
+#> 304   85  Petal.Width             0
+#> 305   85 Sepal.Length             1
+#> 306   85  Sepal.Width             4
+#> 307   86 Petal.Length             2
+#> 308   86  Petal.Width             0
+#> 309   86 Sepal.Length             3
+#> 310   87 Petal.Length             0
+#> 311   87  Petal.Width             2
+#> 312   87 Sepal.Length             4
+#> 313   87  Sepal.Width             3
+#> 314   88 Petal.Length             0
+#> 315   88  Petal.Width             1
+#> 316   88 Sepal.Length             2
+#> 317   88  Sepal.Width             3
+#> 318   89 Petal.Length             0
+#> 319   89  Petal.Width             1
+#> 320   89 Sepal.Length             4
+#> 321   89  Sepal.Width             3
+#> 322   90 Petal.Length             1
+#> 323   90  Petal.Width             1
+#> 324   90 Sepal.Length             2
+#> 325   90  Sepal.Width             0
+#> 326   91 Petal.Length             1
+#> 327   91  Petal.Width             0
+#> 328   92 Petal.Length             0
+#> 329   92  Petal.Width             2
+#> 330   92  Sepal.Width             6
+#> 331   93 Petal.Length             0
+#> 332   93  Petal.Width             1
+#> 333   93 Sepal.Length             2
+#>  [ reached 'max' / getOption("max.print") -- omitted 25 rows ]
+
+
+
+
- - - - + diff --git a/docs/reference/min_depth_interactions.html b/docs/reference/min_depth_interactions.html index a476bb5..9c40f09 100644 --- a/docs/reference/min_depth_interactions.html +++ b/docs/reference/min_depth_interactions.html @@ -1,89 +1,16 @@ - - - - - - - -Calculate mean conditional minimal depth — min_depth_interactions • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Calculate mean conditional minimal depth — min_depth_interactions • randomForestExplainer - - - - - - - - +
-
- -
- -
+
@@ -147,78 +63,66 @@

Calculate mean conditional minimal depth

Calculate mean conditional minimal depth with respect to a vector of variables

-
min_depth_interactions(
-  forest,
-  vars = important_variables(measure_importance(forest)),
-  mean_sample = "top_trees",
-  uncond_mean_sample = mean_sample
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
forest

A randomForest object

vars

A character vector with variables with respect to which conditional minimal depth will be calculated; by default it is extracted by the important_variables function but this may be time consuming

mean_sample

The sample of trees on which conditional mean minimal depth is calculated, possible values are "all_trees", "top_trees", "relevant_trees"

uncond_mean_sample

The sample of trees on which unconditional mean minimal depth is calculated, possible values are "all_trees", "top_trees", "relevant_trees"

- -

Value

- -

A data frame with each observation giving the means of conditional minimal depth and the size of sample for a given interaction

- -

Examples

-
forest <- randomForest::randomForest(Species ~ ., data = iris, ntree = 100) -min_depth_interactions(forest, c("Petal.Width", "Petal.Length")) -
#> Warning: `funs()` was deprecated in dplyr 0.8.0. -#> Please use a list of either functions or lambdas: -#> -#> # Simple named list: -#> list(mean = mean, median = median) -#> -#> # Auto named with `tibble::lst()`: -#> tibble::lst(mean, median) -#> -#> # Using lambdas -#> list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
-
+
+
min_depth_interactions(
+  forest,
+  vars = important_variables(measure_importance(forest)),
+  mean_sample = "top_trees",
+  uncond_mean_sample = mean_sample
+)
+
+ +
+

Arguments

+
forest
+

A randomForest object

+ + +
vars
+

A character vector with variables with respect to which conditional minimal depth will be calculated; by default it is extracted by the important_variables function but this may be time consuming

+ + +
mean_sample
+

The sample of trees on which conditional mean minimal depth is calculated, possible values are "all_trees", "top_trees", "relevant_trees"

+ + +
uncond_mean_sample
+

The sample of trees on which unconditional mean minimal depth is calculated, possible values are "all_trees", "top_trees", "relevant_trees"

+ +
+
+

Value

+ + +

A data frame with each observation giving the means of conditional minimal depth and the size of sample for a given interaction

+
+ +
+

Examples

+
forest <- randomForest::randomForest(Species ~ ., data = iris, ntree = 100)
+min_depth_interactions(forest, c("Petal.Width", "Petal.Length"))
+
+
+
+
- - - - + diff --git a/docs/reference/plot_importance_ggpairs-1.png b/docs/reference/plot_importance_ggpairs-1.png index 3fb3d16..9d30a00 100644 Binary files a/docs/reference/plot_importance_ggpairs-1.png and b/docs/reference/plot_importance_ggpairs-1.png differ diff --git a/docs/reference/plot_importance_ggpairs.html b/docs/reference/plot_importance_ggpairs.html index b7215a6..f1bde26 100644 --- a/docs/reference/plot_importance_ggpairs.html +++ b/docs/reference/plot_importance_ggpairs.html @@ -1,89 +1,16 @@ - - - - - - - -Plot importance measures with ggpairs — plot_importance_ggpairs • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Plot importance measures with ggpairs — plot_importance_ggpairs • randomForestExplainer - - - - - - - - +
-
- -
- -
+
@@ -147,64 +63,63 @@

Plot importance measures with ggpairs

Plot selected measures of importance of variables in a forest using ggpairs

-
plot_importance_ggpairs(
-  importance_frame,
-  measures = NULL,
-  main = "Relations between measures of importance"
-)
- -

Arguments

- - - - - - - - - - - - - - -
importance_frame

A result of using the function measure_importance() to a random forest or a randomForest object

measures

A character vector specifying the measures of importance to be used

main

A string to be used as title of the plot

- -

Value

- -

A ggplot object

- -

Examples

-
forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE, ntree = 200) -frame <- measure_importance(forest, measures = c("mean_min_depth", "times_a_root")) -plot_importance_ggpairs(frame, measures = c("mean_min_depth", "times_a_root")) -
-
+
+
plot_importance_ggpairs(
+  importance_frame,
+  measures = NULL,
+  main = "Relations between measures of importance"
+)
+
+ +
+

Arguments

+
importance_frame
+

A result of using the function measure_importance() to a random forest or a randomForest object

+ + +
measures
+

A character vector specifying the measures of importance to be used

+ + +
main
+

A string to be used as title of the plot

+ +
+
+

Value

+ + +

A ggplot object

+
+ +
+

Examples

+
forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE, ntree = 200)
+frame <- measure_importance(forest, measures = c("mean_min_depth", "times_a_root"))
+plot_importance_ggpairs(frame, measures = c("mean_min_depth", "times_a_root"))
+
+
+
+
+
- - - - + diff --git a/docs/reference/plot_importance_rankings-1.png b/docs/reference/plot_importance_rankings-1.png index 114079f..e2b5eac 100644 Binary files a/docs/reference/plot_importance_rankings-1.png and b/docs/reference/plot_importance_rankings-1.png differ diff --git a/docs/reference/plot_importance_rankings.html b/docs/reference/plot_importance_rankings.html index dbd71d2..b3ad405 100644 --- a/docs/reference/plot_importance_rankings.html +++ b/docs/reference/plot_importance_rankings.html @@ -1,89 +1,16 @@ - - - - - - - -Plot importance measures rankings with ggpairs — plot_importance_rankings • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Plot importance measures rankings with ggpairs — plot_importance_rankings • randomForestExplainer - - - - - - - - +
-
- -
- -
+
@@ -147,64 +63,63 @@

Plot importance measures rankings with ggpairs

Plot against each other rankings of variables according to various measures of importance

-
plot_importance_rankings(
-  importance_frame,
-  measures = NULL,
-  main = "Relations between rankings according to different measures"
-)
- -

Arguments

- - - - - - - - - - - - - - -
importance_frame

A result of using the function measure_importance() to a random forest or a randomForest object

measures

A character vector specifying the measures of importance to be used.

main

A string to be used as title of the plot

- -

Value

- -

A ggplot object

- -

Examples

-
forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE, ntree = 300) -frame <- measure_importance(forest, measures = c("mean_min_depth", "times_a_root")) -plot_importance_ggpairs(frame, measures = c("mean_min_depth", "times_a_root")) -
-
+
+
plot_importance_rankings(
+  importance_frame,
+  measures = NULL,
+  main = "Relations between rankings according to different measures"
+)
+
+ +
+

Arguments

+
importance_frame
+

A result of using the function measure_importance() to a random forest or a randomForest object

+ + +
measures
+

A character vector specifying the measures of importance to be used.

+ + +
main
+

A string to be used as title of the plot

+ +
+
+

Value

+ + +

A ggplot object

+
+ +
+

Examples

+
forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE, ntree = 300)
+frame <- measure_importance(forest, measures = c("mean_min_depth", "times_a_root"))
+plot_importance_ggpairs(frame, measures = c("mean_min_depth", "times_a_root"))
+
+
+
+
+
- - - - + diff --git a/docs/reference/plot_min_depth_distribution-1.png b/docs/reference/plot_min_depth_distribution-1.png index d34731d..3923314 100644 Binary files a/docs/reference/plot_min_depth_distribution-1.png and b/docs/reference/plot_min_depth_distribution-1.png differ diff --git a/docs/reference/plot_min_depth_distribution.html b/docs/reference/plot_min_depth_distribution.html index 6a29fda..e7eb547 100644 --- a/docs/reference/plot_min_depth_distribution.html +++ b/docs/reference/plot_min_depth_distribution.html @@ -1,89 +1,16 @@ - - - - - - - -Plot the distribution of minimal depth in a random forest — plot_min_depth_distribution • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Plot the distribution of minimal depth in a random forest — plot_min_depth_distribution • randomForestExplainer - - - - - - - - +
-
- -
- -
+
@@ -147,83 +63,82 @@

Plot the distribution of minimal depth in a random forest

Plot the distribution of minimal depth in a random forest

-
plot_min_depth_distribution(
-  min_depth_frame,
-  k = 10,
-  min_no_of_trees = 0,
-  mean_sample = "top_trees",
-  mean_scale = FALSE,
-  mean_round = 2,
-  main = "Distribution of minimal depth and its mean"
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
min_depth_frame

A data frame output of min_depth_distribution function or a randomForest object

k

The maximal number of variables with lowest mean minimal depth to be used for plotting

min_no_of_trees

The minimal number of trees in which a variable has to be used for splitting to be used for plotting

mean_sample

The sample of trees on which mean minimal depth is calculated, possible values are "all_trees", "top_trees", "relevant_trees"

mean_scale

Logical: should the values of mean minimal depth be rescaled to the interval [0,1]?

mean_round

The number of digits used for displaying mean minimal depth

main

A string to be used as title of the plot

- -

Value

- -

A ggplot object

- -

Examples

-
forest <- randomForest::randomForest(Species ~ ., data = iris, ntree = 300) -plot_min_depth_distribution(min_depth_distribution(forest)) -
-
+
+
plot_min_depth_distribution(
+  min_depth_frame,
+  k = 10,
+  min_no_of_trees = 0,
+  mean_sample = "top_trees",
+  mean_scale = FALSE,
+  mean_round = 2,
+  main = "Distribution of minimal depth and its mean"
+)
+
+ +
+

Arguments

+
min_depth_frame
+

A data frame output of min_depth_distribution function or a randomForest object

+ + +
k
+

The maximal number of variables with lowest mean minimal depth to be used for plotting

+ + +
min_no_of_trees
+

The minimal number of trees in which a variable has to be used for splitting to be used for plotting

+ + +
mean_sample
+

The sample of trees on which mean minimal depth is calculated, possible values are "all_trees", "top_trees", "relevant_trees"

+ + +
mean_scale
+

Logical: should the values of mean minimal depth be rescaled to the interval [0,1]?

+ + +
mean_round
+

The number of digits used for displaying mean minimal depth

+ + +
main
+

A string to be used as title of the plot

+ +
+
+

Value

+ + +

A ggplot object

+
+ +
+

Examples

+
forest <- randomForest::randomForest(Species ~ ., data = iris, ntree = 300)
+plot_min_depth_distribution(min_depth_distribution(forest))
+
+
+
+
+
- - - - + diff --git a/docs/reference/plot_min_depth_interactions-1.png b/docs/reference/plot_min_depth_interactions-1.png index 926d96a..e1bccaa 100644 Binary files a/docs/reference/plot_min_depth_interactions-1.png and b/docs/reference/plot_min_depth_interactions-1.png differ diff --git a/docs/reference/plot_min_depth_interactions.html b/docs/reference/plot_min_depth_interactions.html index e9926ae..2ee32ea 100644 --- a/docs/reference/plot_min_depth_interactions.html +++ b/docs/reference/plot_min_depth_interactions.html @@ -1,89 +1,16 @@ - - - - - - - -Plot the top mean conditional minimal depth — plot_min_depth_interactions • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Plot the top mean conditional minimal depth — plot_min_depth_interactions • randomForestExplainer - - - - - - - - +
-
- -
- -
+
@@ -147,63 +63,62 @@

Plot the top mean conditional minimal depth

Plot the top mean conditional minimal depth

-
plot_min_depth_interactions(
-  interactions_frame,
-  k = 30,
-  main = paste0("Mean minimal depth for ", paste0(k, " most frequent interactions"))
-)
- -

Arguments

- - - - - - - - - - - - - - -
interactions_frame

A data frame produced by the min_depth_interactions() function or a randomForest object

k

The number of best interactions to plot, if set to NULL then all plotted

main

A string to be used as title of the plot

- -

Value

- -

A ggplot2 object

- -

Examples

-
forest <- randomForest::randomForest(Species ~ ., data = iris, ntree = 100) -plot_min_depth_interactions(min_depth_interactions(forest, c("Petal.Width", "Petal.Length"))) -
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to min; returning Inf
-
+
+
plot_min_depth_interactions(
+  interactions_frame,
+  k = 30,
+  main = paste0("Mean minimal depth for ", paste0(k, " most frequent interactions"))
+)
+
+ +
+

Arguments

+
interactions_frame
+

A data frame produced by the min_depth_interactions() function or a randomForest object

+ + +
k
+

The number of best interactions to plot, if set to NULL then all plotted

+ + +
main
+

A string to be used as title of the plot

+ +
+
+

Value

+ + +

A ggplot2 object

+
+ +
+

Examples

+
forest <- randomForest::randomForest(Species ~ ., data = iris, ntree = 100)
+plot_min_depth_interactions(min_depth_interactions(forest, c("Petal.Width", "Petal.Length")))
+
+
+
+
+
- - - - + diff --git a/docs/reference/plot_multi_way_importance-1.png b/docs/reference/plot_multi_way_importance-1.png index 8c4876d..27d1eab 100644 Binary files a/docs/reference/plot_multi_way_importance-1.png and b/docs/reference/plot_multi_way_importance-1.png differ diff --git a/docs/reference/plot_multi_way_importance.html b/docs/reference/plot_multi_way_importance.html index d29a947..cdbb39f 100644 --- a/docs/reference/plot_multi_way_importance.html +++ b/docs/reference/plot_multi_way_importance.html @@ -1,89 +1,16 @@ - - - - - - - -Multi-way importance plot — plot_multi_way_importance • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Multi-way importance plot — plot_multi_way_importance • randomForestExplainer - - - - - - - - +
-
- -
- -
+
@@ -147,83 +63,82 @@

Multi-way importance plot

Plot two or three measures of importance of variables in a random fores. Choose importance measures from the colnames(importance_frame).

-
plot_multi_way_importance(
-  importance_frame,
-  x_measure = "mean_min_depth",
-  y_measure = "times_a_root",
-  size_measure = NULL,
-  min_no_of_trees = 0,
-  no_of_labels = 10,
-  main = "Multi-way importance plot"
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
importance_frame

A result of using the function measure_importance() to a random forest or a randomForest object

x_measure

The measure of importance to be shown on the X axis

y_measure

The measure of importance to be shown on the Y axis

size_measure

The measure of importance to be shown as size of points (optional)

min_no_of_trees

The minimal number of trees in which a variable has to be used for splitting to be used for plotting

no_of_labels

The approximate number of best variables (according to all measures plotted) to be labeled (more will be labeled in case of ties)

main

A string to be used as title of the plot

- -

Value

- -

A ggplot object

- -

Examples

-
forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE) -plot_multi_way_importance(measure_importance(forest)) -
-
+
+
plot_multi_way_importance(
+  importance_frame,
+  x_measure = "mean_min_depth",
+  y_measure = "times_a_root",
+  size_measure = NULL,
+  min_no_of_trees = 0,
+  no_of_labels = 10,
+  main = "Multi-way importance plot"
+)
+
+ +
+

Arguments

+
importance_frame
+

A result of using the function measure_importance() to a random forest or a randomForest object

+ + +
x_measure
+

The measure of importance to be shown on the X axis

+ + +
y_measure
+

The measure of importance to be shown on the Y axis

+ + +
size_measure
+

The measure of importance to be shown as size of points (optional)

+ + +
min_no_of_trees
+

The minimal number of trees in which a variable has to be used for splitting to be used for plotting

+ + +
no_of_labels
+

The approximate number of best variables (according to all measures plotted) to be labeled (more will be labeled in case of ties)

+ + +
main
+

A string to be used as title of the plot

+ +
+
+

Value

+ + +

A ggplot object

+
+ +
+

Examples

+
forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE)
+plot_multi_way_importance(measure_importance(forest))
+
+
+
+
+
- - - - + diff --git a/docs/reference/plot_predict_interaction-1.png b/docs/reference/plot_predict_interaction-1.png index 3b57dcb..1d61f23 100644 Binary files a/docs/reference/plot_predict_interaction-1.png and b/docs/reference/plot_predict_interaction-1.png differ diff --git a/docs/reference/plot_predict_interaction-2.png b/docs/reference/plot_predict_interaction-2.png index b22e246..685b6ca 100644 Binary files a/docs/reference/plot_predict_interaction-2.png and b/docs/reference/plot_predict_interaction-2.png differ diff --git a/docs/reference/plot_predict_interaction.html b/docs/reference/plot_predict_interaction.html index 4505bef..ebc0ec5 100644 --- a/docs/reference/plot_predict_interaction.html +++ b/docs/reference/plot_predict_interaction.html @@ -1,89 +1,16 @@ - - - - - - - -Plot the prediction of the forest for a grid of values of two numerical variables — plot_predict_interaction • randomForestExplainer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Plot the prediction of the forest for a grid of values of two numerical variables — plot_predict_interaction • randomForestExplainer - - - - - - - - +
-
- -
- -
+
@@ -147,88 +63,88 @@

Plot the prediction of the forest for a grid of values of two numerical vari

Plot the prediction of the forest for a grid of values of two numerical variables

-
plot_predict_interaction(
-  forest,
-  data,
-  variable1,
-  variable2,
-  grid = 100,
-  main = paste0("Prediction of the forest for different values of ", paste0(variable1,
-    paste0(" and ", variable2))),
-  time = NULL
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
forest

A randomForest or ranger object

data

The data frame on which forest was trained

variable1

A character string with the name a numerical predictor that will on X-axis

variable2

A character string with the name a numerical predictor that will on Y-axis

grid

The number of points on the one-dimensional grid on x and y-axis

main

A string to be used as title of the plot

time

A numeric value specifying the time at which to predict survival probability, only +

+
plot_predict_interaction(
+  forest,
+  data,
+  variable1,
+  variable2,
+  grid = 100,
+  main = paste0("Prediction of the forest for different values of ", paste0(variable1,
+    paste0(" and ", variable2))),
+  time = NULL
+)
+
+ +
+

Arguments

+
forest
+

A randomForest or ranger object

+ + +
data
+

The data frame on which forest was trained

+ + +
variable1
+

A character string with the name a numerical predictor that will on X-axis

+ + +
variable2
+

A character string with the name a numerical predictor that will on Y-axis

+ + +
grid
+

The number of points on the one-dimensional grid on x and y-axis

+ + +
main
+

A string to be used as title of the plot

+ + +
time
+

A numeric value specifying the time at which to predict survival probability, only applies to survival forests. If not specified, the time closest to predicted median survival -time is used

+time is used

-

Value

+
+
+

Value

+ -

A ggplot2 object

+

A ggplot2 object

+
-

Examples

-
forest <- randomForest::randomForest(Species ~., data = iris) -plot_predict_interaction(forest, iris, "Petal.Width", "Sepal.Width") -
forest_ranger <- ranger::ranger(Species ~., data = iris) -plot_predict_interaction(forest, iris, "Petal.Width", "Sepal.Width") -
-
+
+

Examples

+
forest <- randomForest::randomForest(Species ~., data = iris)
+plot_predict_interaction(forest, iris, "Petal.Width", "Sepal.Width")
+
+forest_ranger <- ranger::ranger(Species ~., data = iris)
+plot_predict_interaction(forest, iris, "Petal.Width", "Sepal.Width")
+
+
+
+
+
- - - - + diff --git a/docs/sitemap.xml b/docs/sitemap.xml new file mode 100644 index 0000000..589d60d --- /dev/null +++ b/docs/sitemap.xml @@ -0,0 +1,60 @@ + + + + /404.html + + + /articles/index.html + + + /articles/randomForestExplainer.html + + + /authors.html + + + /index.html + + + /news/index.html + + + /reference/explain_forest.html + + + /reference/important_variables.html + + + /reference/index.html + + + /reference/measure_importance.html + + + /reference/min_depth_distribution.html + + + /reference/min_depth_interactions.html + + + /reference/plot_importance_ggpairs.html + + + /reference/plot_importance_rankings.html + + + /reference/plot_min_depth_distribution.html + + + /reference/plot_min_depth_interactions.html + + + /reference/plot_multi_way_importance.html + + + /reference/plot_predict_interaction.html + + + /reference/Your_forest_explained.html + + diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R new file mode 100644 index 0000000..a5bcddb --- /dev/null +++ b/tests/testthat/test-utils.R @@ -0,0 +1,5 @@ +test_that("functions work as expected without warnings", { + + expect_equal(min_na(NA), NA) + expect_equal(max_na(NA), NA) +}) diff --git a/tests/testthat/test_randomForest.R b/tests/testthat/test_randomForest.R index d4b8261..cee7be8 100644 --- a/tests/testthat/test_randomForest.R +++ b/tests/testthat/test_randomForest.R @@ -10,9 +10,9 @@ load(system.file("testdata/test_randomForest.rda", package="randomForestExplaine # save(rf_c, rf_r, rf_u, file = "inst/testdata/test_randomForest.rda") -context("Test randomForest classification forests") +# Test randomForest classification forests ------------------- -test_that("measure_importance works", { +test_that("measure_importance works for randomForest classification forests", { imp_df <- measure_importance(rf_c, mean_sample = "all_trees", measures = c("mean_min_depth", "accuracy_decrease", "gini_decrease", "no_of_nodes", "times_a_root", "p_value")) @@ -20,58 +20,63 @@ test_that("measure_importance works", { c("Petal.Length", "Petal.Width", "Sepal.Length", "Sepal.Width")) }) -test_that("important_variables works", { +test_that("important_variables works for randomForest classification forests", { imp_vars <- important_variables(rf_c, k = 3, measures = c("mean_min_depth", "accuracy_decrease", "gini_decrease", "no_of_nodes", "times_a_root", "p_value")) expect_equal(imp_vars, c("Petal.Width", "Petal.Length", "Sepal.Length")) }) -test_that("min_depth_distribution works", { +test_that("min_depth_distribution works for randomForest classification forests", { min_depth_dist <- min_depth_distribution(rf_c) - expect_equivalent(min_depth_dist[min_depth_dist$tree == 1 & min_depth_dist$variable == "Petal.Width", ]$minimal_depth, - 0) + expect_equal(min_depth_dist[min_depth_dist$tree == 1 & min_depth_dist$variable == "Petal.Width", ]$minimal_depth, 0) }) -test_that("min_depth_interactions works", { +test_that("min_depth_interactions works for randomForest classification forests", { + # depth_int returns matrix min_depth_int <- min_depth_interactions(rf_c, vars = c("Petal.Width")) - expect_equivalent(min_depth_int[min_depth_int$interaction == "Petal.Width:Sepal.Length", ]$mean_min_depth, - 0) + expect_equal( + min_depth_int[min_depth_int$interaction == "Petal.Width:Sepal.Length", ]$mean_min_depth, + 0, + ignore_attr = "dim" + ) }) -test_that("plot_multi_way_importance works", { +test_that("plot_multi_way_importance works for randomForest classification forests", { p <- plot_multi_way_importance(rf_c) expect_silent(print(p)) }) -test_that("plot_min_depth_distribution works", { +test_that("plot_min_depth_distribution works for randomForest classification forests", { p <- plot_min_depth_distribution(rf_c) expect_silent(print(p)) }) -test_that("plot_min_depth_interactions works", { +test_that("plot_min_depth_interacxtions works for randomForest classification forests", { + int_frame <- min_depth_interactions(rf_c) + expect_equal(dim(int_frame), c(16, 6)) p <- plot_min_depth_interactions(rf_c) expect_silent(print(p)) }) -test_that("plot_predict_interaction works", { +test_that("plot_predict_interaction works for randomForest classification forests", { p <- plot_predict_interaction(rf_c, data = iris, variable1 = "Petal.Width", variable2 = "Petal.Length") expect_silent(print(p)) }) -test_that("plot_importance_ggpairs works", { +test_that("plot_importance_ggpairs works for randomForest classification forests", { p <- plot_importance_ggpairs(rf_c) expect_silent(suppressMessages(print(p))) }) -test_that("plot_importance_rankings works", { +test_that("plot_importance_rankings works for randomForest classification forests", { p <- plot_importance_rankings(rf_c) expect_silent(suppressWarnings(suppressMessages(print(p)))) }) -context("Test randomForest regression forests") +# Test randomForest regression forests --------------- -test_that("measure_importance works", { +test_that("measure_importance works for randomForest regression forests ", { imp_df <- measure_importance(rf_r, mean_sample = "all_trees", measures = c("mean_min_depth", "mse_increase", "node_purity_increase", "no_of_nodes", "times_a_root", "p_value")) @@ -79,58 +84,62 @@ test_that("measure_importance works", { c("am", "carb", "cyl", "disp", "drat", "gear", "hp", "qsec", "vs", "wt")) }) -test_that("important_variables works", { +test_that("important_variables works for randomForest regression forests ", { imp_vars <- important_variables(rf_r, k = 3, measures = c("mean_min_depth", "mse_increase", "node_purity_increase", "no_of_nodes", "times_a_root", "p_value")) expect_equal(imp_vars, c("cyl", "disp", "hp", "wt")) }) -test_that("min_depth_distribution works", { +test_that("min_depth_distribution works for randomForest regression forests ", { min_depth_dist <- min_depth_distribution(rf_r) - expect_equivalent(min_depth_dist[min_depth_dist$tree == 1 & min_depth_dist$variable == "cyl", ]$minimal_depth, - 0) + expect_equal( + min_depth_dist[min_depth_dist$tree == 1 & min_depth_dist$variable == "cyl", ]$minimal_depth, + 0) }) -test_that("min_depth_interactions works", { +test_that("min_depth_interactions works for randomForest regression forests ", { min_depth_int <- min_depth_interactions(rf_r, vars = c("cyl")) - expect_equivalent(min_depth_int[min_depth_int$interaction == "cyl:wt", ]$mean_min_depth, - 1) + # returns matrix + expect_equal( + min_depth_int[min_depth_int$interaction == "cyl:wt", ]$mean_min_depth, + 1, + ignore_attr = "dim") }) -test_that("plot_multi_way_importance works", { +test_that("plot_multi_way_importance works for randomForest regression forests ", { p <- plot_multi_way_importance(rf_r) expect_silent(suppressWarnings(print(p))) }) -test_that("plot_min_depth_distribution works", { +test_that("plot_min_depth_distribution works for randomForest regression forests ", { p <- plot_min_depth_distribution(rf_r) expect_silent(print(p)) }) -test_that("plot_min_depth_interactions works", { +test_that("plot_min_depth_interactions works for randomForest regression forests ", { p <- plot_min_depth_interactions(rf_r) expect_silent(print(p)) }) -test_that("plot_predict_interaction works", { +test_that("plot_predict_interaction works for randomForest regression forests ", { p <- plot_predict_interaction(rf_r, data = mtcars, variable1 = "cyl", variable2 = "wt") expect_silent(print(p)) }) -test_that("plot_importance_ggpairs works", { +test_that("plot_importance_ggpairs works for randomForest regression forests ", { p <- plot_importance_ggpairs(rf_r) expect_silent(suppressWarnings(suppressMessages(print(p)))) }) -test_that("plot_importance_rankings works", { +test_that("plot_importance_rankings works for randomForest regression forests ", { p <- plot_importance_rankings(rf_r) expect_silent(suppressWarnings(suppressMessages(print(p)))) }) -context("Test randomForest unsupervised forests") +# Test randomForest unsupervised forests ---------------------------------- -test_that("measure_importance works", { +test_that("measure_importance works for randomForest unsupervised forests", { imp_df <- measure_importance(rf_u, mean_sample = "all_trees", measures = c("mean_min_depth", "accuracy_decrease", "gini_decrease", "no_of_nodes", "times_a_root", "p_value")) @@ -138,36 +147,41 @@ test_that("measure_importance works", { c("Petal.Length", "Petal.Width", "Sepal.Length", "Sepal.Width", "Species")) }) -test_that("important_variables works", { +test_that("important_variables works for randomForest unsupervised forests", { imp_vars <- important_variables(rf_u, k = 3, measures = c("mean_min_depth", "accuracy_decrease", "gini_decrease", "no_of_nodes", "times_a_root", "p_value")) expect_equal(imp_vars, c("Petal.Length", "Sepal.Length", "Species")) }) -test_that("min_depth_distribution works", { +test_that("min_depth_distribution works for randomForest unsupervised forests", { min_depth_dist <- min_depth_distribution(rf_u) - expect_equivalent(min_depth_dist[min_depth_dist$tree == 1 & min_depth_dist$variable == "Sepal.Width", ]$minimal_depth, - 0) + expect_equal( + min_depth_dist[min_depth_dist$tree == 1 & min_depth_dist$variable == "Sepal.Width", ]$minimal_depth, + 0) }) -test_that("min_depth_interactions works", { +test_that("min_depth_interactions works for randomForest unsupervised forests", { min_depth_int <- min_depth_interactions(rf_u, vars = c("Petal.Width")) - expect_equivalent(min_depth_int[min_depth_int$interaction == "Petal.Width:Sepal.Length", ]$mean_min_depth, - 1) + # returns matrix + expect_equal( + min_depth_int[min_depth_int$interaction == "Petal.Width:Sepal.Length", ]$mean_min_depth, + 1, + ignore_attr = "dim" + ) }) -test_that("plot_multi_way_importance works", { +test_that("plot_multi_way_importance works for randomForest unsupervised forests", { p <- plot_multi_way_importance(rf_u) expect_silent(suppressWarnings(print(p))) }) -test_that("plot_min_depth_distribution works", { +test_that("plot_min_depth_distribution works for randomForest unsupervised forests", { p <- plot_min_depth_distribution(rf_u) expect_silent(print(p)) }) -test_that("plot_min_depth_interactions works", { +test_that("plot_min_depth_interactions works for randomForest unsupervised forests", { p <- plot_min_depth_interactions(rf_u) expect_silent(print(p)) }) @@ -177,12 +191,12 @@ test_that("plot_predict_interaction does not work for unsupervised forests", { expect_null(p) }) -test_that("plot_importance_ggpairs works", { +test_that("plot_importance_ggpairs works for randomForest unsupervised forests", { p <- plot_importance_ggpairs(rf_u) expect_silent(suppressWarnings(suppressMessages(print(p)))) }) -test_that("plot_importance_rankings works", { +test_that("plot_importance_rankings works for randomForest unsupervised forests", { p <- plot_importance_rankings(rf_u) expect_silent(suppressWarnings(suppressMessages(print(p)))) }) diff --git a/tests/testthat/test_ranger.R b/tests/testthat/test_ranger.R index 84b1841..2131450 100644 --- a/tests/testthat/test_ranger.R +++ b/tests/testthat/test_ranger.R @@ -10,65 +10,71 @@ load(system.file("testdata/test_ranger.rda", package="randomForestExplainer", mu # ranger_s <- ranger(Surv(futime, fustat) ~ ., data = ovarian, importance = "impurity", num.trees = 2) # save(ranger_c, ranger_r, ranger_s, ovarian, file = "inst/testdata/test_ranger.rda") -context("Test ranger classification forests") +# Test ranger classification forests --------------------- -test_that("measure_importance works", { +test_that("measure_importance works for ranger classification forests", { imp_df <- measure_importance(ranger_c, mean_sample = "all_trees", measures = c("mean_min_depth", "impurity", "no_of_nodes", "times_a_root", "p_value")) expect_equal(as.character(imp_df$variable), c("Petal.Length", "Petal.Width", "Sepal.Length", "Sepal.Width")) }) -test_that("important_variables works", { +test_that("important_variables works for ranger classification forests", { imp_vars <- important_variables(ranger_c, k = 3, measures = c("mean_min_depth", "impurity", "no_of_nodes", "times_a_root", "p_value")) expect_equal(imp_vars, c("Petal.Width", "Sepal.Length", "Petal.Length")) }) -test_that("min_depth_distribution works", { +test_that("min_depth_distribution works for ranger classification forests", { min_depth_dist <- min_depth_distribution(ranger_c) - expect_equivalent(min_depth_dist[min_depth_dist$tree == 1 & min_depth_dist$variable == "Petal.Width", ]$minimal_depth, - 0) + expect_equal( + min_depth_dist[min_depth_dist$tree == 1 & min_depth_dist$variable == "Petal.Width", ]$minimal_depth, + 0 + ) }) -test_that("min_depth_interactions works", { +test_that("min_depth_interactions works for ranger classification forests", { min_depth_int <- min_depth_interactions(ranger_c, vars = c("Petal.Width")) - expect_equivalent(min_depth_int[min_depth_int$interaction == "Petal.Width:Sepal.Length", ]$mean_min_depth, - 1.5) + # returns matrix + expect_equal( + min_depth_int[min_depth_int$interaction == "Petal.Width:Sepal.Length", ]$mean_min_depth, + 1.5, + ignore_attr = "dim" + ) }) -test_that("plot_multi_way_importance works", { +test_that("plot_multi_way_importance works for ranger classification forests", { p <- plot_multi_way_importance(ranger_c) expect_silent(print(p)) }) -test_that("plot_min_depth_distribution works", { +test_that("plot_min_depth_distribution works for ranger classification forests", { p <- plot_min_depth_distribution(ranger_c) expect_silent(print(p)) }) -test_that("plot_min_depth_interactions works", { +test_that("plot_min_depth_interactions works for ranger classification forests", { p <- plot_min_depth_interactions(ranger_c) expect_silent(print(p)) }) -test_that("plot_predict_interaction works", { +test_that("plot_predict_interaction works for ranger classification forests", { p <- plot_predict_interaction(ranger_c, data = iris, variable1 = "Petal.Width", variable2 = "Petal.Length") expect_silent(print(p)) }) -test_that("plot_importance_ggpairs works", { +test_that("plot_importance_ggpairs works for ranger classification forests", { p <- plot_importance_ggpairs(ranger_c) expect_silent(suppressMessages(print(p))) }) -test_that("plot_importance_rankings works", { +test_that("plot_importance_rankings works for ranger classification forests", { p <- plot_importance_rankings(ranger_c) expect_silent(suppressWarnings(suppressMessages(print(p)))) }) -context("Test ranger regression forests") +# Test ranger regression forests ------- test_that("measure_importance works", { imp_df <- measure_importance(ranger_r, mean_sample = "all_trees", @@ -87,14 +93,20 @@ test_that("important_variables works", { test_that("min_depth_distribution works", { min_depth_dist <- min_depth_distribution(ranger_r) - expect_equivalent(min_depth_dist[min_depth_dist$tree == 2 & min_depth_dist$variable == "cyl", ]$minimal_depth, - 0) + expect_equal( + min_depth_dist[min_depth_dist$tree == 2 & min_depth_dist$variable == "cyl", ]$minimal_depth, + 0, + ignore_attr = "dim" + ) }) test_that("min_depth_interactions works", { min_depth_int <- min_depth_interactions(ranger_r, vars = c("cyl")) - expect_equivalent(min_depth_int[min_depth_int$interaction == "cyl:wt", ]$mean_min_depth, - 0.5) + expect_equal( + min_depth_int[min_depth_int$interaction == "cyl:wt", ]$mean_min_depth, + 0.5, + ignore_attr = "dim" + ) }) test_that("plot_multi_way_importance works", { @@ -127,9 +139,9 @@ test_that("plot_importance_rankings works", { expect_silent(suppressWarnings(suppressMessages(print(p)))) }) -context("Test ranger survival forests") +# Test ranger survival forests -------------------------- -test_that("measure_importance works", { +test_that("measure_importance works for ranger survival forests", { imp_df <- measure_importance(ranger_s, mean_sample = "all_trees", measures = c("mean_min_depth", "impurity", "no_of_nodes", "times_a_root", "p_value")) @@ -137,51 +149,56 @@ test_that("measure_importance works", { c("age", "ecog.ps", "resid.ds", "rx")) }) -test_that("important_variables works", { +test_that("important_variables works for ranger survival forests", { imp_vars <- important_variables(ranger_s, k = 3, measures = c("mean_min_depth", "impurity", "no_of_nodes", "times_a_root", "p_value")) expect_equal(imp_vars, c("age", "ecog.ps", "rx")) }) -test_that("min_depth_distribution works", { +test_that("min_depth_distribution works for ranger survival forests", { min_depth_dist <- min_depth_distribution(ranger_s) - expect_equivalent(min_depth_dist[min_depth_dist$tree == 1 & min_depth_dist$variable == "age", ]$minimal_depth, - 0) + expect_equal( + min_depth_dist[min_depth_dist$tree == 1 & min_depth_dist$variable == "age", ]$minimal_depth, + 0 + ) }) -test_that("min_depth_interactions works", { +test_that("min_depth_interactions works for ranger survival forests", { min_depth_int <- min_depth_interactions(ranger_s, vars = c("age")) - expect_equivalent(min_depth_int[min_depth_int$interaction == "age:ecog.ps", ]$mean_min_depth, - 0.5) + # returns matrix + expect_equal( + min_depth_int[min_depth_int$interaction == "age:ecog.ps", ]$mean_min_depth, + 0.5, + ignore_attr = "dim") }) -test_that("plot_multi_way_importance works", { +test_that("plot_multi_way_importance works for ranger survival forests", { p <- plot_multi_way_importance(ranger_s) expect_silent(suppressWarnings(print(p))) }) -test_that("plot_min_depth_distribution works", { +test_that("plot_min_depth_distribution works for ranger survival forests", { p <- plot_min_depth_distribution(ranger_s) expect_silent(print(p)) }) -test_that("plot_min_depth_interactions works", { +test_that("plot_min_depth_interactions works for ranger survival forests", { p <- plot_min_depth_interactions(ranger_s) expect_silent(print(p)) }) -test_that("plot_predict_interaction works", { +test_that("plot_predict_interaction works for ranger survival forests", { p <- plot_predict_interaction(ranger_s, data = ovarian, variable1 = "age", variable2 = "ecog.ps") expect_silent(print(p)) }) -test_that("plot_importance_ggpairs works", { +test_that("plot_importance_ggpairs works for ranger survival forests", { p <- plot_importance_ggpairs(ranger_s) expect_silent(suppressWarnings(suppressMessages(print(p)))) }) -test_that("plot_importance_rankings works", { +test_that("plot_importance_rankings works for ranger survival forests", { p <- plot_importance_rankings(ranger_s) expect_silent(suppressWarnings(suppressMessages(print(p)))) })