plotFeatures: Plot the importance and influence of features.

View source: R/plotFeatures.R

plotFeaturesR Documentation

Plot the importance and influence of features.

Description

Returns a ggplot object with variables importance (across all categorical levels for factor variables) and variable per-level influence. It uses the ggpubr package to combine plots.

Usage

plotFeatures(
  decision_ensemble,
  levels_order = NULL,
  colour_low = "#E69F00",
  colour_mid = "grey87",
  colour_high = "#0072B2",
  return_all = FALSE
)

Arguments

decision_ensemble

stable decision ensemble (see stabilitySelection).

levels_order

optional, order for variables levels on the influence plot

colour_low

colour for the negative feature influence values (default: yellowish)

colour_mid

colour for the null feature influence values (default: light grey)

colour_high

colour for the positive feature influence values (default: blue)

return_all

TRUE, returns the table of feature importance and influences and each plot separated (default = FALSE).

Value

2 ggplots arranged in a row with ggpubr; if return_all = TRUE, returns plots separately in a list , as well as the tables used to create plots.

Examples

library(randomForest)
library(caret)

# import data and fit model
data(iris)
mod <- randomForest(Species ~ ., data = iris)

# Fit a decision ensemble to predict the species setosa (vs versicolor and
# virginica): no regularization (no decision pruning, discretization,
# bootstrapping, or decision filtering)
endo_setosa <- model2DE(model = mod, model_type = "rf", data = iris[, -5]
    , target = iris$Species, classPos = "setosa"
    , filter = FALSE, discretize = FALSE, prune = FALSE)

# Only decision pruning (default = TRUE) and discretization (default in 2
# categories, we want 3 categories so we change K); no bootstrapping or
# decision filtering.
endo_setosa <- model2DE(model = mod, model_type = "rf", data = iris[, -5]
    , target = iris$Species, classPos = "setosa"
    , filter = FALSE, discretize = TRUE, K = 3)

# idem but run it in parallel on 2 threads
endo_setosa <- model2DE(model = mod, model_type = "rf", data = iris[, -5]
    , target = iris$Species, classPos = "setosa"
    , filter = FALSE, discretize = TRUE, K = 3
    , in_parallel = TRUE, n_cores = 2)

# Plot the decision ensemble:
# Plants from the setosa species have small petal and narrow long sepals.
plotFeatures(endo_setosa, levels_order = c("Low", "Medium", "High"))
plotNetwork(endo_setosa, hide_isolated_nodes = FALSE, layout = "fr")

aruaud/endoR documentation built on Jan. 25, 2025, 2:20 a.m.