Skip to contents

Plot variable importances and cumulative approximation of R^2

Usage

g_var_imp(
  object,
  feat_labels = NULL,
  textsize = 16,
  top_k = NULL,
  pdp_plot_sample = TRUE,
  show_pdp_plot = TRUE,
  var_imp_type = "normalized",
  logodds_to_prob = FALSE,
  plot_ratios = if (show_pdp_plot) c(3, 2, 2) else c(3, 2)
)

Arguments

object

(sculpture)

feat_labels

(NULL) or named character vector providing the variable labels.

textsize

Size of text.

top_k

(NULL) or number to show only the most k important variables.

pdp_plot_sample

(logical) Sample PDP for faster ploting? Defaults to TRUE.

show_pdp_plot

(logical) Show plot with PDP ranges? Defaults to TRUE.

var_imp_type

(character) One of c("normalized", "absolute", "ice", "ice_orig_mod"). Defaults to "normalized". "ice" is only valid for a rough sculpture.

logodds_to_prob

(logical) Only valid for binary response and sculptures built on the log-odds scale. Defaults to FALSE (i.e. no effect). If TRUE, then the y-values are transformed through inverse logit function 1 / (1 + exp(-x)).

plot_ratios

(numeric) Used in the layout matrix of gridExtra::arrangeGrob(). If show_pdp_plot, then the default is c(3,2,2), making the first plot 3 units wide and the other two plots 2 units wide. If !show_pdp_plot, then the default is c(3,2), making the first plot 3 units wide and the second plot 2 units wide. Note that the length needs to be 3 if show_pdp_plot or 2 if !show_pdp_plot.

Value

grob. Use grid::grid.draw to plot the output (grid::grid.newpage resets the plotting area).

Examples

df <- mtcars
df$vs <- as.factor(df$vs)
model <- rpart::rpart(
  hp ~ mpg + carb + vs,
  data = df,
  control = rpart::rpart.control(minsplit = 10)
)
model_predict <- function(x) predict(model, newdata = x)
covariates <- c("mpg", "carb", "vs")
pm <- sample_marginals(df[covariates], n = 50, seed = 5)

rs <- sculpt_rough(
  dat = pm,
  model_predict_fun = model_predict,
  n_ice = 10,
  seed = 1,
  verbose = 0
)

# optionally define labels
labels <- structure(
  toupper(covariates), # labels
  names = covariates # current (old) names
)
vi <- g_var_imp(rs, feat_labels = labels)
grid::grid.draw(vi)