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. IfNULL(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). IfNULL, uses the default for the forest type.
Details
Different engines compute importances differently:
rpart::rpart(),xgboost::xgb.importance(), andlightgbm::lgb.importance()follow the change in the objective function (e.g., Gini, MSE, gain, ...) as the tree is constructed and reports the aggregate improvement in these statistics as importance.randomForest::importance()andranger::ranger()produce standard permutation-based importance scores.grf::variable_importance()states that a "simple weighted sum of how many times feature i was split on at each depth in the forest" is used.
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.