Various metrics related to model sculpting
var_imp.Rd
Various metrics related to model sculpting
Arguments
- object
sculpture
- newdata
(Optional) Data to calculate the importance from. If omitted, the data that were provided to build the sculpture are used.
Functions
calc_dir_var_imp()
: Direct variable importancecalc_cumul_R2()
: Calculate cumulative approximation of R^2
Examples
df <- mtcars
df$vs <- as.factor(df$vs)
model <- rpart::rpart(
hp ~ mpg + carb + vs,
data = df,
control = rpart::rpart.control(minsplit = 10)
)
model_predict <- function(x) predict(model, newdata = x)
covariates <- c("mpg", "carb", "vs")
pm <- sample_marginals(df[covariates], n = 50, seed = 5)
rs <- sculpt_rough(
dat = pm,
model_predict_fun = model_predict,
n_ice = 10,
seed = 1,
verbose = 0
)
# show direct variable importance
calc_dir_var_imp(rs)
#> feature variance variance_total ratio
#> <fctr> <num> <num> <num>
#> 1: mpg 1936.4199 2296.917 0.8430518
#> 2: carb 346.5405 2296.917 0.1508720
#> 3: vs 0.0000 2296.917 0.0000000
# show cumulative approximation R^2
calc_cumul_R2(rs)
#> feature R2
#> <fctr> <num>
#> 1: mpg 0.849128
#> 2: carb 1.000000
#> 3: vs 1.000000