## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set(collapse = TRUE, comment = "#>") has_rf <- requireNamespace("randomForest", quietly = TRUE) ## ----------------------------------------------------------------------------- library(rankimp) judges <- rbind( permutation_seed1 = c(1, 2, 3, 4, 5), permutation_seed2 = c(1, 2, 3, 5, 4), permutation_seed3 = c(2, 1, 3, 4, 5), shap = c(1, 3, 2, 4, 5), impurity = c(1, 2, 4, 3, 5), loco = c(2, 1, 3, 5, 4) ) colnames(judges) <- c("income", "age", "balance", "region", "tenure") cr <- consensus_rank(judges) cr ## ----------------------------------------------------------------------------- item_consensus(cr) ## ----------------------------------------------------------------------------- set.seed(1) cb <- rank_confsets(cr, n_boot = 500) cb ## ----fig.width = 6, fig.height = 3.5------------------------------------------ autoplot(cb) ## ----------------------------------------------------------------------------- prob_topk(cb, k = 2) ## ----------------------------------------------------------------------------- rank_select(cb, threshold = 3) ## ----eval = has_rf------------------------------------------------------------ set.seed(7) n <- 80 sim <- as.data.frame(matrix(rnorm(n * 8), n, 8)) names(sim) <- paste0("x", 1:8) sim$y <- 2 * sim$x1 + 0.60 * sim$x2 + 0.55 * sim$x3 + 0.50 * sim$x4 + 0.45 * sim$x5 + rnorm(n, sd = 1) set.seed(1) forest <- randomForest::randomForest(y ~ ., data = sim, ntree = 200) set.seed(2) sim_panel <- importance_judges(forest, methods = c("permutation", "mdi"), data = sim, target = "y", seeds = 1:3) cr_sim <- consensus_rank(sim_panel) cr_sim ## ----eval = has_rf------------------------------------------------------------ set.seed(3) by_judges <- rank_confsets(cr_sim, n_boot = 500) set.seed(3) by_data <- rank_confsets(cr_sim, type = "data") by_data ## ----eval = has_rf------------------------------------------------------------ rank_select(by_judges, threshold = 3) rank_select(by_data, threshold = 3)