-
-
Notifications
You must be signed in to change notification settings - Fork 168
/
predict_parts.Rd
144 lines (118 loc) · 5.16 KB
/
predict_parts.Rd
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/predict_parts.R
\name{predict_parts}
\alias{predict_parts}
\alias{predict_parts_break_down}
\alias{predict_parts_ibreak_down}
\alias{predict_parts_shap}
\alias{predict_parts_oscillations}
\alias{predict_parts_oscillations_uni}
\alias{predict_parts_oscillations_emp}
\alias{predict_parts_break_down_interactions}
\alias{predict_parts_shap_aggregated}
\alias{predict_parts_kernel_shap}
\alias{predict_parts_kernel_shap_break_down}
\alias{predict_parts_kernel_shap_aggreagted}
\alias{variable_attribution}
\title{Instance Level Parts of the Model Predictions}
\usage{
predict_parts(
explainer,
new_observation,
...,
N = if (substr(type, 1, 4) == "osci") 500 else NULL,
type = "break_down"
)
predict_parts_oscillations(explainer, new_observation, ...)
predict_parts_oscillations_uni(
explainer,
new_observation,
variable_splits_type = "uniform",
...
)
predict_parts_oscillations_emp(
explainer,
new_observation,
variable_splits = NULL,
variables = colnames(explainer$data),
...
)
predict_parts_break_down(explainer, new_observation, ...)
predict_parts_break_down_interactions(explainer, new_observation, ...)
predict_parts_shap(explainer, new_observation, ...)
predict_parts_shap_aggregated(explainer, new_observation, ...)
predict_parts_kernel_shap(explainer, new_observation, ...)
predict_parts_kernel_shap_break_down(explainer, new_observation, ...)
predict_parts_kernel_shap_aggreagted(explainer, new_observation, ...)
variable_attribution(
explainer,
new_observation,
...,
N = if (substr(type, 1, 4) == "osci") 500 else NULL,
type = "break_down"
)
}
\arguments{
\item{explainer}{a model to be explained, preprocessed by the \code{explain} function}
\item{new_observation}{a new observation for which predictions need to be explained}
\item{...}{other parameters that will be passed to \code{iBreakDown::break_down}}
\item{N}{the maximum number of observations used for calculation of attributions. By default NULL (use all) or 500 (for oscillations).}
\item{type}{the type of variable attributions. Either \code{shap}, \code{aggregated_shap}, \code{oscillations}, \code{oscillations_uni},
\code{oscillations_emp}, \code{break_down}, \code{break_down_interactions}, \code{kernel_shap}, \code{kernel_shap_break_down} or \code{kernel_shap_aggregated}.}
\item{variable_splits_type}{how variable grids shall be calculated? Will be passed to \code{\link[ingredients]{ceteris_paribus}}.}
\item{variable_splits}{named list of splits for variables. It is used by oscillations based measures. Will be passed to \code{\link[ingredients]{ceteris_paribus}}.}
\item{variables}{names of variables for which splits shall be calculated. Will be passed to \code{\link[ingredients]{ceteris_paribus}}.}
}
\value{
Depending on the \code{type} there are different classes of the resulting object.
It's a data frame with calculated average response.
}
\description{
Instance Level Variable Attributions as Break Down, SHAP, aggregated SHAP or Oscillations explanations.
Model prediction is decomposed into parts that are attributed for particular variables.
From DALEX version 1.0 this function calls the \code{\link[iBreakDown]{break_down}} or
\code{\link[iBreakDown:break_down_uncertainty]{shap}} functions from the \code{iBreakDown} package or
\code{\link[ingredients:ceteris_paribus]{ceteris_paribus}} from the \code{ingredients} package or
\code{\link[kernelshap:kernelshap]{kernelshap}} from the \code{kernelshap} package.
Find information how to use the \code{break_down} method here: \url{https://ema.drwhy.ai/breakDown.html}.
Find information how to use the \code{shap} method here: \url{https://ema.drwhy.ai/shapley.html}.
Find information how to use the \code{oscillations} method here: \url{https://ema.drwhy.ai/ceterisParibusOscillations.html}.
Find information how to use the \code{kernelshap} method here: \url{https://modeloriented.github.io/kernelshap/}
aSHAP method provides explanations for a set of observations based on SHAP.
}
\examples{
library(DALEX)
new_dragon <- data.frame(
year_of_birth = 200,
height = 80,
weight = 12.5,
scars = 0,
number_of_lost_teeth = 5
)
model_lm <- lm(life_length ~ year_of_birth + height +
weight + scars + number_of_lost_teeth,
data = dragons)
explainer_lm <- explain(model_lm,
data = dragons,
y = dragons$year_of_birth,
label = "model_lm")
bd_lm <- predict_parts_break_down(explainer_lm, new_observation = new_dragon)
head(bd_lm)
plot(bd_lm)
\donttest{
library("ranger")
model_ranger <- ranger(life_length ~ year_of_birth + height +
weight + scars + number_of_lost_teeth,
data = dragons, num.trees = 50)
explainer_ranger <- explain(model_ranger,
data = dragons,
y = dragons$year_of_birth,
label = "model_ranger")
bd_ranger <- predict_parts_break_down(explainer_ranger, new_observation = new_dragon)
head(bd_ranger)
plot(bd_ranger)
}
}
\references{
Explanatory Model Analysis. Explore, Explain, and Examine Predictive Models. \url{https://ema.drwhy.ai/}
}