Skip to content

Methods for computing variable importance scores via the model object using a common interface.

Usage

# S3 method for class 'ObliqueForest'
var_imp(object, complete = TRUE, ...)

# S3 method for class 'cforest'
var_imp(object, complete = TRUE, ...)

# S3 method for class 'grf'
var_imp(object, complete = TRUE, ...)

# S3 method for class 'lgb.Booster'
var_imp(object, complete = TRUE, feature_names = NULL, ...)

# S3 method for class 'party'
var_imp(object, complete = TRUE, ...)

# S3 method for class 'randomForest'
var_imp(object, complete = TRUE, type = NULL, ...)

# S3 method for class 'ranger'
var_imp(object, complete = TRUE, ...)

# S3 method for class 'rpart'
var_imp(object, complete = TRUE, ...)

# S3 method for class 'xgb.Booster'
var_imp(object, complete = TRUE, feature_names = NULL, ...)

Arguments

object

A model object.

complete

A logical to filling absent importance values with zeros.

...

Arguments passed to importance functions (if any).

feature_names

Character vector of feature names to include when complete = TRUE. For xgboost models, the model object does not store unused feature names, so this parameter allows you to specify the complete feature set. If NULL (default), only features that appear in at least one tree will be included.

type

Character string specifying which importance measure to extract. For classification forests, options are "gini" (default, uses MeanDecreaseGini), "accuracy" (uses MeanDecreaseAccuracy), or a class name. For regression forests, options are "mse" (default, uses IncNodePurity) or "permutation" (uses %IncMSE). If NULL, uses the default for the forest type.

Value

A tibble with columns term and estimate.

Details

Different engines compute importances differently:

Keep in mind that, for rpart::rpart(), the importance calculation is affected by competing and surrogate splits. Consequently, there might be non-zero importances for predictors that were not used in any actual split in the tree. To make the splits and importances align, use the options maxcompete = 0 and maxsurrogate = 0.