This function calculate ceteris paribus profiles for selected data points.

ceteris_paribus(explainer, observations, y = NULL,
  variable_splits = NULL, variables = NULL, grid_points = 101)

Arguments

explainer

a model to be explained, preprocessed by function `DALEX::explain()`.

observations

set of observarvation for which profiles are to be calculated

y

true labels for `observations`. If specified then will be added to ceteris paribus plots.

variable_splits

named list of splits for variables, in most cases created with `calculate_variable_splits()`. If NULL then it will be calculated based on validation data avaliable in the `explainer`.

variables

names of variables for which profiles shall be calculated. Will be passed to `calculate_variable_splits()`. If NULL then all variables from the validation data will be used.

grid_points

number of points for profile. Will be passed to `calculate_variable_splits()`.

Value

An object of the class 'ceteris_paribus_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) apartments_small <- select_sample(apartmentsTest, 10) cp_rf <- ceteris_paribus(explainer_rf, apartments_small) cp_rf
#> Top profiles : #> m2.price construction.year surface floor no.rooms district _yhat_ #> 8946 2174 1920 123 8 4 Wola 2871.626 #> 8946.1 2174 1921 123 8 4 Wola 2896.045 #> 8946.2 2174 1922 123 8 4 Wola 2901.677 #> 8946.3 2174 1923 123 8 4 Wola 2891.101 #> 8946.4 2174 1923 123 8 4 Wola 2891.101 #> 8946.5 2174 1924 123 8 4 Wola 2890.361 #> _vname_ _ids_ _label_ #> 8946 construction.year 8946 randomForest #> 8946.1 construction.year 8946 randomForest #> 8946.2 construction.year 8946 randomForest #> 8946.3 construction.year 8946 randomForest #> 8946.4 construction.year 8946 randomForest #> 8946.5 construction.year 8946 randomForest #> #> #> Top observations: #> m2.price construction.year surface floor no.rooms district _yhat_ #> 8946 2174 1959 123 8 4 Wola 2386.002 #> 4458 4319 1927 68 8 2 Ochota 4222.164 #> 7384 5501 1929 95 5 3 Srodmiescie 4646.023 #> 5450 2810 1982 124 10 5 Ochota 3062.748 #> 6744 1770 1982 143 9 6 Ursynow 2171.529 #> 6688 2796 1938 75 7 3 Wola 3045.947 #> _label_ #> 8946 randomForest #> 4458 randomForest #> 7384 randomForest #> 5450 randomForest #> 6744 randomForest #> 6688 randomForest
cp_rf <- ceteris_paribus(explainer_rf, apartments_small, y = apartments_small$m2.price) cp_rf
#> Top profiles : #> m2.price construction.year surface floor no.rooms district _yhat_ #> 8946 2174 1920 123 8 4 Wola 2871.626 #> 8946.1 2174 1921 123 8 4 Wola 2896.045 #> 8946.2 2174 1922 123 8 4 Wola 2901.677 #> 8946.3 2174 1923 123 8 4 Wola 2891.101 #> 8946.4 2174 1923 123 8 4 Wola 2891.101 #> 8946.5 2174 1924 123 8 4 Wola 2890.361 #> _vname_ _ids_ _label_ #> 8946 construction.year 8946 randomForest #> 8946.1 construction.year 8946 randomForest #> 8946.2 construction.year 8946 randomForest #> 8946.3 construction.year 8946 randomForest #> 8946.4 construction.year 8946 randomForest #> 8946.5 construction.year 8946 randomForest #> #> #> Top observations: #> m2.price construction.year surface floor no.rooms district _yhat_ #> 8946 2174 1959 123 8 4 Wola 2386.002 #> 4458 4319 1927 68 8 2 Ochota 4222.164 #> 7384 5501 1929 95 5 3 Srodmiescie 4646.023 #> 5450 2810 1982 124 10 5 Ochota 3062.748 #> 6744 1770 1982 143 9 6 Ursynow 2171.529 #> 6688 2796 1938 75 7 3 Wola 3045.947 #> _y_ _label_ #> 8946 2174 randomForest #> 4458 4319 randomForest #> 7384 5501 randomForest #> 5450 2810 randomForest #> 6744 1770 randomForest #> 6688 2796 randomForest