View source: R/plot_feature_importance.R
plot.feature_importance_explainer | R Documentation |
This function plots variable importance calculated as changes in the loss function after variable drops.
It uses output from feature_importance
function that corresponds to
permutation based measure of variable importance.
Variables are sorted in the same order in all panels.
The order depends on the average drop out loss.
In different panels variable contributions may not look like sorted if variable
importance is different in different in different models.
## S3 method for class 'feature_importance_explainer' plot( x, ..., max_vars = NULL, show_boxplots = TRUE, bar_width = 10, desc_sorting = TRUE, title = "Feature Importance", subtitle = NULL )
x |
a feature importance explainer produced with the |
... |
other explainers that shall be plotted together |
max_vars |
maximum number of variables that shall be presented for for each model.
By default |
show_boxplots |
logical if |
bar_width |
width of bars. By default |
desc_sorting |
logical. Should the bars be sorted descending? By default TRUE |
title |
the plot's title, by default |
subtitle |
the plot's subtitle. By default - |
Find more details in the Feature Importance Chapter.
a ggplot2
object
Explanatory Model Analysis. Explore, Explain, and Examine Predictive Models. https://ema.drwhy.ai/
library("DALEX") library("ingredients") model_titanic_glm <- glm(survived ~ gender + age + fare, data = titanic_imputed, family = "binomial") explain_titanic_glm <- explain(model_titanic_glm, data = titanic_imputed[,-8], y = titanic_imputed[,8]) fi_rf <- feature_importance(explain_titanic_glm, B = 1) plot(fi_rf) library("ranger") model_titanic_rf <- ranger(survived ~., data = titanic_imputed, probability = TRUE) explain_titanic_rf <- explain(model_titanic_rf, data = titanic_imputed[,-8], y = titanic_imputed[,8], label = "ranger forest", verbose = FALSE) fi_rf <- feature_importance(explain_titanic_rf) plot(fi_rf) HR_rf_model <- ranger(status~., data = HR, probability = TRUE) explainer_rf <- explain(HR_rf_model, data = HR, y = HR$status, verbose = FALSE, precalculate = FALSE) fi_rf <- feature_importance(explainer_rf, type = "raw", max_vars = 3, loss_function = DALEX::loss_cross_entropy) head(fi_rf) plot(fi_rf) HR_glm_model <- glm(status == "fired"~., data = HR, family = "binomial") explainer_glm <- explain(HR_glm_model, data = HR, y = as.numeric(HR$status == "fired")) fi_glm <- feature_importance(explainer_glm, type = "raw", loss_function = DALEX::loss_root_mean_square) head(fi_glm) plot(fi_glm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.