## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set(collapse = TRUE, comment = "#>") has_rf <- requireNamespace("randomForest", quietly = TRUE) ## ----eval = has_rf------------------------------------------------------------ library(rankimp) set.seed(1) fit <- randomForest::randomForest(mpg ~ ., data = mtcars, ntree = 200) round(importance_permutation(fit, mtcars, "mpg", n_perm = 3), 3) ## ----------------------------------------------------------------------------- scores <- rbind( permutation = c(income = 0.31, age = 0.12, balance = 0.12, region = 0.03), impurity = c(income = 0.44, age = 0.20, balance = 0.05, region = 0.02) ) importance_to_rank(scores) ## ----eval = has_rf------------------------------------------------------------ J <- importance_judges( fit, methods = c("permutation", "mdi"), data = mtcars, target = "mpg", seeds = 1:2, n_perm = 2 ) J ## ----eval = has_rf------------------------------------------------------------ attr(J, "provenance") ## ----------------------------------------------------------------------------- judges <- rbind( c(1, 2, 3, 4), c(1, 2, 3, 4), c(1, 3, 2, 4), c(2, 1, 3, 4), c(1, 2, 4, 3), c(2, 1, 4, 3) ) colnames(judges) <- c("income", "age", "balance", "region") cb <- rank_confsets(consensus_rank(judges), n_boot = 200) cb ## ----------------------------------------------------------------------------- rank_select(cb, threshold = 2) prob_topk(cb, k = 2)