calculate_variable_profile: Internal Function for Individual Variable Profiles

Description Usage Arguments Details Value Examples

View source: R/calculate_profiles.R

Description

This function calculates individual variable profiles (ceteris paribus profiles), i.e. series of predictions from a model calculated for observations with altered single coordinate.

Usage

1
2
calculate_variable_profile(data, variable_splits, model,
  predict_function = predict, ...)

Arguments

data

set of observations. Profile will be calculated for every observation (every row)

variable_splits

named list of vectors. Elements of the list are vectors with points in which profiles should be calculated. See an example for more details.

model

a model that will be passed to the predict_function

predict_function

function that takes data and model and returns numeric predictions. Note that the ... arguments will be passed to this function.

...

other parameters that will be passed to the predict_function

Details

Note that calculate_variable_profile function is S3 generic. If you want to work on non standard data sources (like H2O ddf, external databases) you should overload it.

Value

a data frame with profiles for selected variables and selected observations

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library("DALEX2")
 ## Not run: 
library("randomForest")
set.seed(59)
apartments_rf_model <- randomForest(m2.price ~ construction.year + surface + floor +
                                      no.rooms + district, data = apartments)
vars <- c("construction.year", "surface", "floor", "no.rooms", "district")
variable_splits <- calculate_variable_split(apartments, vars)
new_apartment <- apartments_test[1:10, ]
profiles <- calculate_variable_profile(new_apartment, variable_splits,
                               apartments_rf_model)
profiles

# only subset of observations
small_apartments <- select_sample(apartments_test, n = 10)
small_apartments
small_profiles <- calculate_variable_profile(small_apartments, variable_splits,
                               apartments_rf_model)
small_profiles

# neighbors for a selected observation
new_apartment <- apartments[1, 2:6]
small_apartments <- select_neighbours(apartments_test, new_apartment, n = 10)
small_apartments
small_profiles <- calculate_variable_profile(small_apartments, variable_splits,
                               apartments_rf_model)
new_apartment
small_profiles

## End(Not run)

pbiecek/ceterisParibus2 documentation built on Sept. 16, 2019, 6:26 p.m.