This function calculate local importance measure in eight variants. We obtain eight variants measure through the possible options of three parameters such as absolute_deviation, point and density.

local_variable_importance(
  profiles,
  data,
  absolute_deviation = TRUE,
  point = TRUE,
  density = TRUE,
  grid_points = 101
)

Arguments

profiles

data.frame generated by DALEX::predict_profile(), DALEX::individual_profile() or ingredients::ceteris_paribus()

data

data.frame with raw data to model

absolute_deviation

logical parameter, if absolute_deviation = TRUE then measure is calculated as absolute deviation, else is calculated as a root from average squares

point

logical parameter, if point = TRUE then measure is calculated as a distance from f(x), else measure is calculated as a distance from average profiles

density

logical parameter, if density = TRUE then measure is weighted based on the density of variable, else is not weighted

grid_points

maximum number of points for profile calculations, the default values is 101, the same as in ingredients::ceteris_paribus(), if you use a different on, you should also change here

Value

A data.frame of the class local_variable_importance. It's a data.frame with calculated local variable importance measure.

Examples

library("DALEX") data(apartments) library("randomForest") apartments_rf_model <- randomForest(m2.price ~ construction.year + surface + floor + no.rooms, data = apartments) explainer_rf <- explain(apartments_rf_model, data = apartmentsTest[,2:5], y = apartmentsTest$m2.price)
#> Preparation of a new explainer is initiated #> -> model label : randomForest ( default ) #> -> data : 9000 rows 4 cols #> -> target variable : 9000 values #> -> predict function : yhat.randomForest will be used ( default ) #> -> predicted values : numerical, min = 2088.426 , mean = 3515.222 , max = 5384.985 #> -> model_info : package randomForest , ver. 4.6.14 , task regression ( default ) #> -> residual function : difference between y and yhat ( default ) #> -> residuals : numerical, min = -1277.025 , mean = -3.698933 , max = 2085.661 #> A new explainer has been created!
new_apartment <- data.frame(construction.year = 1998, surface = 88, floor = 2L, no.rooms = 3) profiles <- predict_profile(explainer_rf, new_apartment) library("vivo") local_variable_importance(profiles, apartments[,2:5], absolute_deviation = TRUE, point = TRUE, density = TRUE)
#> variable_name measure _label_model_ #> 1 construction.year 179.61607 randomForest #> 2 surface 287.59996 randomForest #> 3 floor 274.95305 randomForest #> 4 no.rooms 64.27073 randomForest #> _label_method_ #> 1 absolute_deviation = TRUE, point = TRUE, density = TRUE #> 2 absolute_deviation = TRUE, point = TRUE, density = TRUE #> 3 absolute_deviation = TRUE, point = TRUE, density = TRUE #> 4 absolute_deviation = TRUE, point = TRUE, density = TRUE
local_variable_importance(profiles, apartments[,2:5], absolute_deviation = TRUE, point = TRUE, density = FALSE)
#> variable_name measure _label_model_ #> 1 construction.year 178.67763 randomForest #> 2 surface 283.38958 randomForest #> 3 floor 257.88508 randomForest #> 4 no.rooms 59.82041 randomForest #> _label_method_ #> 1 absolute_deviation = TRUE, point = TRUE, density = FALSE #> 2 absolute_deviation = TRUE, point = TRUE, density = FALSE #> 3 absolute_deviation = TRUE, point = TRUE, density = FALSE #> 4 absolute_deviation = TRUE, point = TRUE, density = FALSE
local_variable_importance(profiles, apartments[,2:5], absolute_deviation = TRUE, point = FALSE, density = TRUE)
#> variable_name measure _label_model_ #> 1 construction.year 132.73394 randomForest #> 2 surface 299.56126 randomForest #> 3 floor 212.61949 randomForest #> 4 no.rooms 66.79469 randomForest #> _label_method_ #> 1 absolute_deviation = TRUE, point = FALSE, density = TRUE #> 2 absolute_deviation = TRUE, point = FALSE, density = TRUE #> 3 absolute_deviation = TRUE, point = FALSE, density = TRUE #> 4 absolute_deviation = TRUE, point = FALSE, density = TRUE