predict_parts {survex} | R Documentation |
Instance Level Parts of Survival Model Predictions
Description
This function decomposes the model prediction into individual parts, which are attributions of particular variables. The explanations can be made via the SurvLIME and SurvSHAP(t) methods.
Usage
predict_parts(explainer, ...)
## S3 method for class 'surv_explainer'
predict_parts(
explainer,
new_observation,
...,
N = NULL,
type = "survshap",
output_type = "survival",
explanation_label = NULL
)
Arguments
explainer |
an explainer object - model preprocessed by the |
... |
other parameters which are passed to |
new_observation |
a new observation for which prediction need to be explained |
N |
the number of observations used for calculation of attributions. If |
type |
if |
output_type |
either |
explanation_label |
a label that can overwrite explainer label (useful for multiple explanations for the same explainer/model) |
Value
An object of class "predict_parts_survival"
and additional classes depending on the type of explanations. It is a list with the element result
containing the results of the calculation.
Additional parameters
There are additional parameters that are passed to internal functions
for
survlime
-
N
- a positive integer, number of observations generated in the neighbourhood -
distance_metric
- character, name of the distance metric to be used, only"euclidean"
is implemented -
kernel_width
- a numeric, parameter used for calculating weights, by default it'ssqrt(ncol(data)*0.75)
-
sampling_method
- character, name of the method of generating neighbourhood, only"gaussian"
is implemented -
sample_around_instance
- logical, if the neighbourhood should be generated with the new observation as the center (default), or should the mean of the whole dataset be used as the center -
max_iter
- a numeric, maximal number of iteration for the optimization problem -
categorical_variables
- character vector, names of variables that should be treated as categories (factors are included by default) -
k
- a small positive number > 1, added to chf before taking log, so that weigths aren't negative
-
for
survshap
-
y_true
- a two element numeric vector or matrix of one row and two columns, the first element being the true observed time and the second the status of the observation, used for plotting -
calculation_method
- a character, either"kernelshap"
for use ofkernelshap
library (providing faster Kernel SHAP with refinements) or"exact_kernel"
for exact Kernel SHAP estimation -
aggregation_method
- a character, either"mean_absolute"
or"integral"
,"max_absolute"
,"sum_of_squares"
-
References
[1] KrzyziĆski, Mateusz, et al. "SurvSHAP(t): Time-dependent explanations of machine learning survival models." Knowledge-Based Systems 262 (2023): 110234
[2] Kovalev, Maxim S., et al. "SurvLIME: A method for explaining machine learning survival models." Knowledge-Based Systems 203 (2020): 106164.
Examples
library(survival)
library(survex)
cph <- coxph(Surv(time, status) ~ ., data = veteran, model = TRUE, x = TRUE, y = TRUE)
cph_exp <- explain(cph)
cph_predict_parts_survshap <- predict_parts(cph_exp, new_observation = veteran[1, -c(3, 4)])
head(cph_predict_parts_survshap$result)
plot(cph_predict_parts_survshap)
cph_predict_parts_survlime <- predict_parts(
cph_exp,
new_observation = veteran[1, -c(3, 4)],
type = "survlime"
)
head(cph_predict_parts_survlime$result)
plot(cph_predict_parts_survlime, type = "local_importance")