This function calculate an empirical density of raw data based on variable split from Ceteris Paribus profiles. Then calculated weight for values generated by DALEX::predict_profile(), DALEX::individual_profile() or ingredients::ceteris_paribus().

calculate_weight(profiles, data, variable_split)

Arguments

profiles

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

data

data.frame with raw data to model

variable_split

list generated by vivo::calculate_variable_split()

Value

Return an weight based on empirical density.

Examples

library("DALEX", warn.conflicts = FALSE, quietly = TRUE)
#> Welcome to DALEX (version: 2.0). #> Find examples and detailed introduction at: https://pbiecek.github.io/ema/
data(apartments) split <- vivo::calculate_variable_split(apartments, variables = colnames(apartments), grid_points = 101) library("randomForest", warn.conflicts = FALSE, quietly = TRUE)
#> randomForest 4.6-14
#> Type rfNews() to see new features/changes/bug fixes.
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 = 2105.619 , mean = 3515.128 , max = 5346.334 #> -> model_info : package randomForest , ver. 4.6.14 , task regression ( default ) #> -> residual function : difference between y and yhat ( default ) #> -> residuals : numerical, min = -1235.195 , mean = -3.604187 , max = 2168.808 #> 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") calculate_weight(profiles, data = apartments[, 2:5], variable_split = split)
#> $construction.year #> [1] 0.004 0.004 0.011 0.013 0.005 0.012 0.012 0.011 0.016 0.011 0.015 0.000 #> [13] 0.003 0.016 0.008 0.011 0.012 0.013 0.011 0.011 0.012 0.000 0.008 0.014 #> [25] 0.011 0.007 0.006 0.012 0.013 0.014 0.013 0.000 0.014 0.017 0.011 0.008 #> [37] 0.010 0.008 0.009 0.007 0.017 0.000 0.018 0.011 0.016 0.010 0.009 0.010 #> [49] 0.010 0.009 0.013 0.000 0.007 0.011 0.016 0.011 0.010 0.018 0.010 0.009 #> [61] 0.006 0.000 0.016 0.003 0.014 0.008 0.005 0.011 0.011 0.006 0.013 0.000 #> [73] 0.009 0.017 0.009 0.015 0.008 0.012 0.015 0.012 0.015 0.000 0.011 0.016 #> [85] 0.009 0.013 0.015 0.012 0.012 0.007 0.009 0.000 0.009 0.010 0.015 0.014 #> [97] 0.004 0.010 0.010 0.012 0.003 #> #> $surface #> [1] 0.009 0.009 0.004 0.007 0.026 0.010 0.005 0.008 0.006 0.012 0.015 0.007 #> [13] 0.004 0.004 0.017 0.011 0.014 0.014 0.006 0.007 0.012 0.006 0.008 0.008 #> [25] 0.015 0.009 0.014 0.012 0.010 0.011 0.012 0.008 0.011 0.011 0.021 0.006 #> [37] 0.008 0.012 0.006 0.006 0.013 0.005 0.004 0.007 0.016 0.007 0.006 0.016 #> [49] 0.008 0.009 0.017 0.009 0.008 0.003 0.016 0.008 0.005 0.020 0.009 0.004 #> [61] 0.012 0.004 0.005 0.007 0.012 0.007 0.014 0.026 0.010 0.006 0.018 0.009 #> [73] 0.009 0.009 0.014 0.002 0.009 0.008 0.010 0.006 0.017 0.006 0.007 0.017 #> [85] 0.012 0.009 0.011 0.016 0.004 0.001 0.015 0.007 0.003 0.005 0.019 0.004 #> [97] 0.012 0.016 0.010 0.017 0.013 #> #> $floor #> [1] 0.090 0.090 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 #> [13] 0.116 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.087 #> [25] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.086 0.000 #> [37] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.095 0.000 0.000 #> [49] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.104 0.000 0.000 0.000 #> [61] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.103 0.000 0.000 0.000 0.000 #> [73] 0.000 0.000 0.000 0.000 0.000 0.000 0.103 0.000 0.000 0.000 0.000 0.000 #> [85] 0.000 0.000 0.000 0.000 0.000 0.108 0.000 0.000 0.000 0.000 0.000 0.000 #> [97] 0.000 0.000 0.000 0.000 0.108 #> #> $no.rooms #> [1] 0.099 0.099 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 #> [13] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.202 0.000 0.000 0.000 #> [25] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 #> [37] 0.000 0.000 0.000 0.000 0.231 0.000 0.000 0.000 0.000 0.000 0.000 0.000 #> [49] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 #> [61] 0.223 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 #> [73] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.198 0.000 0.000 0.000 #> [85] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 #> [97] 0.000 0.000 0.000 0.000 0.047 #>