vi: Variable importance

Description Usage Arguments Value References Examples

View source: R/vi.R

Description

Compute variable importance scores for the predictors in a model.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
vi(object, ...)

## Default S3 method:
vi(
  object,
  method = c("model", "firm", "permute", "shap"),
  feature_names = NULL,
  FUN = NULL,
  var_fun = NULL,
  ice = FALSE,
  abbreviate_feature_names = NULL,
  sort = TRUE,
  decreasing = TRUE,
  scale = FALSE,
  rank = FALSE,
  ...
)

## S3 method for class 'model_fit'
vi(object, ...)

## S3 method for class 'WrappedModel'
vi(object, ...)

## S3 method for class 'Learner'
vi(object, ...)

Arguments

object

A fitted model object (e.g., a "randomForest" object) or an object that inherits from class "vi".

...

Additional optional arguments to be passed on to vi_model, vi_firm, vi_permute, or vi_shap.

method

Character string specifying the type of variable importance (VI) to compute. Current options are "model" (the default), for model-specific VI scores (see vi_model for details), "firm", for variance-based VI scores (see vi_firm for details), "permute", for permutation-based VI scores (see ' vi_permute for details), or "shap", for Shapley-based VI scores. For more details on the variance-based methods, see Greenwell et al. (2018) and Scholbeck et al. (2019).

feature_names

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

FUN

Deprecated. Use var_fun instead.

var_fun

List with two components, "cat" and "con", containing the functions to use to quantify the variability of the feature effects (e.g., partial dependence values) 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). Only applies when method = "firm".

ice

Logical indicating whether or not to estimate feature effects using individual conditional expectation (ICE) curves. Only applies when method = "firm". Default is FALSE. Setting ice = TRUE is preferred whenever strong interaction effects are potentially present.

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.

rank

Logical indicating whether or not to rank the variable importance scores (i.e., convert to integer ranks). Default is FALSE. Potentially useful when comparing variable importance scores across different models using different methods.

Value

A tidy data frame (i.e., a "tibble" object) with at least two columns: Variable and Importance. For "lm"/"glm"-like objects, an additional column, called Sign, is also included which includes the sign (i.e., POS/NEG) of the original coefficient. If method = "permute" and nsim > 1, then an additional column, StDev, giving the standard deviation of the permutation-based variable importance scores is included.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#
# 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 = "firm", ice = TRUE)
vi(mtcars.ppr, method = "firm", ice = TRUE,
   var_fun = list("con" = mad, "cat" = function(x) diff(range(x)) / 4))

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

Example output

Attaching package:vipThe following object is masked frompackage:utils:

    vi

# A tibble: 10 x 2
   Variable Importance
   <chr>         <dbl>
 1 wt           3.44  
 2 hp           2.57  
 3 gear         1.85  
 4 qsec         1.56  
 5 cyl          0.743 
 6 am           0.690 
 7 vs           0.448 
 8 drat         0.245 
 9 carb         0.0870
10 disp         0.0248
# A tibble: 10 x 2
   Variable Importance
   <chr>         <dbl>
 1 wt           3.87  
 2 hp           2.85  
 3 gear         2.14  
 4 qsec         1.71  
 5 cyl          0.949 
 6 am           0.723 
 7 vs           0.470 
 8 drat         0.297 
 9 carb         0.102 
10 disp         0.0317

vip documentation built on Dec. 17, 2020, 5:08 p.m.