plot_varimp: Plot a Model's Variable Importance

plot_varimpR Documentation

Plot a Model's Variable Importance

Description

Draw importance recorded by a rtemis Supervised or SupervisedRes object, or computed from a SHAP explanation by get_varimp, using rtemis.draw::draw_varimp().

Usage

plot_varimp(x, ...)

Arguments

x

rtemis::Supervised, rtemis::SupervisedRes or rtemis::SHAP: Fitted model result or explanation.

...

Additional arguments to rtemis.draw::draw_varimp(), including measure, type, top_n, rank_by, decreasing, bar_width, summary, absent, and title. Fold IDs come from the model and cannot be overridden.

Details

Named measures and variable identities are preserved. Resampled records retain their fold IDs before summarizing. The first measure in the first available fold is selected when measure is omitted; columns missing in other folds are unavailable scores. The full fold list is passed to the renderer, including folds with no importance result.

CART's importance and LightGBM's Gain, Cover, and Frequency come from sparse split summaries: omitted variables in a reporting fold have zero importance. These measures use absent = "zero". Other measures use absent = "missing"; pass absent explicitly to declare another contract. Explicit NA values and wholly unavailable folds are always kept missing.

Use type = "boxplot" for resampled fold distributions with all contributing scores overlaid. Summary bars remain the default. Both views share selection, ranking, and the producer's missing-score contract. Ordinary models have no fold distribution and require the bar view.

A SHAP explanation is drawn from the mean absolute contribution of each feature, with one measure per class for a multiclass outcome.

Models without any importance records produce an informative error. The default title names the algorithm; title = NULL omits it. See rtemis.draw::draw_varimp() for selection, ranking, and missing-score semantics.

Value

htmlwidget: ECharts importance bars or fold distributions.

Examples


model <- train(
  mtcars[, c("wt", "hp", "mpg")],
  hyperparameters = setup_GLM(), verbosity = 0L
)
plot_varimp(model)
features <- mtcars[, c("wt", "hp")]
plot_varimp(explain(model, features, background = features, verbosity = 0L))


rtemis documentation built on Oct. 20, 2026, 1:06 a.m.