This function calculates what if scores for grid of values spanned by two variables.

what_if_2d(explainer, observation, grid_points = 101,
  selected_variables = NULL)

Arguments

explainer

a model to be explained, preprocessed by the 'DALEX::explain' function

observation

a new observarvation for which predictions need to be explained

grid_points

number of points used for response path. Will be used for both variables

selected_variables

if specified, then only these variables will be explained

Value

An object of the class 'what_if_2d_explainer'. It's a data frame with calculated average responses.

Examples

library("DALEX")
library("randomForest") set.seed(59) apartments_rf_model <- randomForest(m2.price ~ construction.year + surface + floor + no.rooms + district, data = apartments) explainer_rf <- explain(apartments_rf_model, data = apartmentsTest[,2:6], y = apartmentsTest$m2.price) new_apartment <- apartmentsTest[1, ] new_apartment
#> m2.price construction.year surface floor no.rooms district #> 1001 4644 1976 131 3 5 Srodmiescie
wi_rf_2d <- what_if_2d(explainer_rf, observation = new_apartment, selected_variables = c("surface", "floor", "no.rooms")) wi_rf_2d
#> y_hat new_x1 new_x2 vname1 vname2 label #> 1001 4851.829 20 1.00 surface floor randomForest #> 1001.1 4851.829 20 1.09 surface floor randomForest #> 1001.2 4851.829 20 1.18 surface floor randomForest #> 1001.3 4851.829 20 1.27 surface floor randomForest #> 1001.4 4851.829 20 1.36 surface floor randomForest #> 1001.5 4851.829 20 1.45 surface floor randomForest
plot(wi_rf_2d)