
tidy up dataframe containing model feature importance
Source:R/alluvial_model_response.R
tidy_imp.Rdreturns dataframe with exactly two columns, vars and imp and aggregates dummy encoded variables. Helper function called by all functions that take an imp parameter. Can be called manually if formula for aggregating dummy encoded variables must be modified.
Examples
# randomforest
df = mtcars2[, ! names(mtcars2) %in% 'ids' ]
m = randomForest::randomForest( disp ~ ., df)
imp = m$importance
tidy_imp(imp, df)
#> # A tibble: 10 × 2
#> vars imp
#> <chr> <dbl>
#> 1 cyl 105250.
#> 2 mpg 81248.
#> 3 hp 73445.
#> 4 wt 70898.
#> 5 drat 47462.
#> 6 gear 23399.
#> 7 qsec 23065.
#> 8 vs 13312.
#> 9 carb 7973.
#> 10 am 2363.