Plot the raw or summarized feature importances as a boxplot, scatter plot, line plot, or bar plot with or without 1 SD error bars.
Usage
plot_feature_importance(
fit_results,
eval_results = NULL,
evaluator_name = NULL,
vary_params = NULL,
feature_col,
show_max_features = NULL,
show = c("errorbar", "bar"),
...
)
Arguments
- fit_results
A tibble, as returned by the
fit
method.- eval_results
A list of result tibbles, as returned by the
evaluate
method.- evaluator_name
Name of
Evaluator
containing results to plot. To compute the evaluation summary results from scratch or if the evaluation summary results have not yet been evaluated, set toNULL
.- vary_params
A vector of parameter names that are varied across in the
Experiment
.- feature_col
A character string identifying the column in
fit_results
with the feature names or IDs.- show_max_features
Maximum number of features to plot.
- show
Character vector with elements being one of "boxplot", "point", "line", "bar", "errorbar", "ribbon" indicating what plot layer(s) to construct.
- ...
Additional arguments to pass to
plot_eval_summary()
. This includes arguments for plotting and for passing intosummarize_feature_importance()
.
Value
If interactive = TRUE
, returns a plotly
object if
plot_by
is NULL
and a list of plotly
objects if
plot_by
is not NULL
. If interactive = FALSE
, returns
a ggplot
object if plot_by
is NULL
and a list of
ggplot
objects if plot_by
is not NULL
.
See also
Other feature_selection_funs:
eval_feature_importance_funs
,
eval_feature_selection_curve_funs
,
eval_feature_selection_err_funs
,
plot_feature_selection_curve()
,
plot_feature_selection_err()
Examples
# generate example fit_results data
fit_results <- tibble::tibble(
.rep = rep(1:2, times = 2),
.dgp_name = c("DGP1", "DGP1", "DGP2", "DGP2"),
.method_name = c("Method"),
feature_info = lapply(
1:4,
FUN = function(i) {
tibble::tibble(
# feature names
feature = c("featureA", "featureB", "featureC"),
# estimated feature importance scores
est_importance = c(10, runif(2, min = -2, max = 2))
)
}
)
)
# generate example eval_results data
eval_results <- list(
`Feature Importance` = summarize_feature_importance(
fit_results,
nested_data = "feature_info",
feature_col = "feature",
imp_col = "est_importance"
)
)
# create bar plot using pre-computed evaluation results
plt <- plot_feature_importance(fit_results = fit_results,
eval_results = eval_results,
evaluator_name = "Feature Importance",
feature_col = "feature")
# or alternatively, create the same plot without pre-computing evaluation results
plt <- plot_feature_importance(fit_results,
nested_data = "feature_info",
feature_col = "feature",
imp_col = "est_importance")
# can customize plot (see plot_eval_summary() for possible arguments)
plt <- plot_feature_importance(fit_results = fit_results,
eval_results = eval_results,
evaluator_name = "Feature Importance",
feature_col = "feature",
errorbar_args = list(width = .5, position = "dodge"),
bar_args = list(width = .5))