Learn R Programming

vip (version 0.1.2)

vi: Variable Importance

Description

Compute variable importance scores for the predictors in a model.

Usage

vi(object, method = c("model", "pdp", "ice", "permute"), feature_names,
  FUN = NULL, abbreviate_feature_names = NULL, sort = TRUE,
  decreasing = TRUE, scale = FALSE, ...)

Arguments

object

A fitted model object (e.g., a "randomForest" object).

method

Character string specifying the type of variable importance (VI) to compute. Current options are "model" (for model-based VI scores), "pdp" (for PDP-based VI scores), "ice" (for ICE-based VI scores), and "permute" (for permutation-based VI scores). The default is "model". For details on the PDP/ICE-based method, see the reference below.

feature_names

Character string giving the names of the predictor variables (i.e., features) of interest.

FUN

List with two components, "cat" and "con", containing the functions to use for categorical and continuous features, respectively. If NULL, the standard deviation is used for continuous features. For categorical features, the range statistic is used (i.e., (max - min) / 4).

abbreviate_feature_names

Integer specifying the length at which to abbreviate feature names. Default is NULL which results in no abbreviation (i.e., the full name of each feature will be printed).

sort

Logical indicating whether or not to order the sort the variable importance scores. Default is TRUE.

decreasing

Logical indicating whether or not the variable importance scores should be sorted in descending (TRUE) or ascending (FALSE) order of importance. Default is TRUE.

scale

Logical indicating whether or not to scale the variable importance scores so that the largest is 100. Default is FALSE.

...

Additional optional arguments.

Value

A tidy data frame (i.e., a "tibble" object) with two columns: Variable and Importance. For "glm"-like object, an additional column, called Sign, is also included which includes the sign (i.e., POS/NEG) of the original coefficient.

References

Greenwell, B. M., Boehmke, B. C., and McCarthy, A. J. A Simple and Effective Model-Based Variable Importance Measure. arXiv preprint arXiv:1805.04755 (2018).

Examples

Run this code
# NOT RUN {
#
# A projection pursuit regression example
#

# Load the sample data
data(mtcars)

# Fit a projection pursuit regression model
mtcars.ppr <- ppr(mpg ~ ., data = mtcars, nterms = 1)

# Compute variable importance scores
vi(mtcars.ppr, method = "ice")

# Plot variable importance scores
vip(mtcars.ppr, method = "ice")
# }

Run the code above in your browser using DataLab