Skip to contents

Extracts variable importance scores from models fitted with rf(), rf_repeat(), or rf_spatial().

Usage

get_importance(model)

Arguments

model

Model object from rf(), rf_repeat(), or rf_spatial().

Value

Data frame with columns variable (character) and importance (numeric), sorted by decreasing importance.

Details

For spatial models (rf_spatial()) with many spatial predictors, this function returns aggregated importance statistics for spatial predictors to improve readability. Non-spatial models return per-variable importance scores directly.

Examples

data(plants_rf)

# Extract variable importance
importance <- get_importance(plants_rf)
head(importance)
#>                   variable importance
#> 1     climate_bio1_average   1949.457
#> 2         human_population   1595.806
#> 3      climate_hypervolume   1188.702
#> 4            bias_area_km2   1177.989
#> 5 human_population_density   1026.905
#> 6  human_footprint_average   1021.417

# View top 5 most important variables
importance[1:5, ]
#>                   variable importance
#> 1     climate_bio1_average   1949.457
#> 2         human_population   1595.806
#> 3      climate_hypervolume   1188.702
#> 4            bias_area_km2   1177.989
#> 5 human_population_density   1026.905