This explainer works for individual observations. For each observation it calculates Local Conditional Expectation (LCE) profiles for selected variables.
local_conditional_expectations(explainer, observations, y = NULL, variable_splits = NULL, variables = NULL, grid_points = 101)
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 local conditional expectations 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()`. |
An object of the class 'ceteris_paribus_explainer'. A data frame with calculated LCE profiles.
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 = apartments[,2:6], y = apartments$m2.price) new_apartment <- apartments[1, ] lce_rf <- local_conditional_expectations(explainer_rf, new_apartment) lce_rf#> Top profiles : #> m2.price construction.year surface floor no.rooms district _yhat_ #> 1 5897 1920 21.84884 3.087808 0.9151128 Srodmiescie 5450.533 #> 1.1 5897 1921 21.94433 3.085148 0.9176852 Srodmiescie 5490.713 #> 1.2 5897 1922 22.03982 3.082487 0.9202575 Srodmiescie 5485.823 #> 1.3 5897 1923 22.13531 3.079826 0.9228298 Srodmiescie 5498.118 #> 1.4 5897 1924 22.23080 3.077165 0.9254022 Srodmiescie 5509.683 #> 1.5 5897 1925 22.32629 3.074504 0.9279745 Srodmiescie 5477.263 #> _vname_ _ids_ _label_ #> 1 construction.year 1 randomForest #> 1.1 construction.year 1 randomForest #> 1.2 construction.year 1 randomForest #> 1.3 construction.year 1 randomForest #> 1.4 construction.year 1 randomForest #> 1.5 construction.year 1 randomForest #> #> #> Top observations: #> m2.price construction.year surface floor no.rooms district _yhat_ #> 1 5897 1953 25 3 1 Srodmiescie 5447.656 #> _label_ #> 1 randomForestlce_rf <- local_conditional_expectations(explainer_rf, new_apartment, y = new_apartment$m2.price) lce_rf#> Top profiles : #> m2.price construction.year surface floor no.rooms district _yhat_ #> 1 5897 1920 21.84884 3.087808 0.9151128 Srodmiescie 5450.533 #> 1.1 5897 1921 21.94433 3.085148 0.9176852 Srodmiescie 5490.713 #> 1.2 5897 1922 22.03982 3.082487 0.9202575 Srodmiescie 5485.823 #> 1.3 5897 1923 22.13531 3.079826 0.9228298 Srodmiescie 5498.118 #> 1.4 5897 1924 22.23080 3.077165 0.9254022 Srodmiescie 5509.683 #> 1.5 5897 1925 22.32629 3.074504 0.9279745 Srodmiescie 5477.263 #> _vname_ _ids_ _label_ #> 1 construction.year 1 randomForest #> 1.1 construction.year 1 randomForest #> 1.2 construction.year 1 randomForest #> 1.3 construction.year 1 randomForest #> 1.4 construction.year 1 randomForest #> 1.5 construction.year 1 randomForest #> #> #> Top observations: #> m2.price construction.year surface floor no.rooms district _yhat_ _y_ #> 1 5897 1953 25 3 1 Srodmiescie 5447.656 5897 #> _label_ #> 1 randomForest