Performs an ALE for one or more features.
Usage
ALE(
model,
variable = NULL,
data = NULL,
K = 10,
ALE_type = c("equidistant", "quantile"),
plot = TRUE,
parallel = FALSE,
...
)
# S3 method for citodnn
ALE(
model,
variable = NULL,
data = NULL,
K = 10,
ALE_type = c("equidistant", "quantile"),
plot = TRUE,
parallel = FALSE,
...
)
# S3 method for citodnnBootstrap
ALE(
model,
variable = NULL,
data = NULL,
K = 10,
ALE_type = c("equidistant", "quantile"),
plot = TRUE,
parallel = FALSE,
...
)
Arguments
- model
a model created by
dnn
- variable
variable as string for which the PDP should be done
- data
data on which ALE is performed on, if NULL training data will be used.
- K
number of neighborhoods original feature space gets divided into
- ALE_type
method on how the feature space is divided into neighborhoods.
- plot
plot ALE or not
- parallel
parallelize over bootstrap models or not
- ...
arguments passed to
predict
Value
A list of plots made with 'ggplot2' consisting of an individual plot for each defined variable.
Explanation
Accumulated Local Effect plots (ALE) quantify how the predictions change when the features change. They are similar to partial dependency plots but are more robust to feature collinearity.
Mathematical details
If the defined variable is a numeric feature, the ALE is performed. Here, the non centered effect for feature j with k equally distant neighborhoods is defined as:
\( \hat{\tilde{f}}_{j,ALE}(x)=\sum_{k=1}^{k_j(x)}\frac{1}{n_j(k)}\sum_{i:x_{j}^{(i)}\in{}N_j(k)}\left[\hat{f}(z_{k,j},x^{(i)}_{\setminus{}j})-\hat{f}(z_{k-1,j},x^{(i)}_{\setminus{}j})\right]\)
Where \(N_j(k)\) is the k-th neighborhood and \(n_j(k)\) is the number of observations in the k-th neighborhood.
The last part of the equation, \(\left[\hat{f}(z_{k,j},x^{(i)}_{\setminus{}j})-\hat{f}(z_{k-1,j},x^{(i)}_{\setminus{}j})\right]\) represents the difference in model prediction when the value of feature j is exchanged with the upper and lower border of the current neighborhood.
Examples
# \donttest{
if(torch::torch_is_installed()){
library(cito)
# Build and train Network
nn.fit<- dnn(Sepal.Length~., data = datasets::iris)
ALE(nn.fit, variable = "Petal.Length")
}
#> Loss at epoch 1: 3.942534, lr: 0.01000
#> Loss at epoch 2: 0.312205, lr: 0.01000
#> Loss at epoch 3: 0.218533, lr: 0.01000
#> Loss at epoch 4: 0.286899, lr: 0.01000
#> Loss at epoch 5: 0.180689, lr: 0.01000
#> Loss at epoch 6: 0.218854, lr: 0.01000
#> Loss at epoch 7: 0.150527, lr: 0.01000
#> Loss at epoch 8: 0.167121, lr: 0.01000
#> Loss at epoch 9: 0.122504, lr: 0.01000
#> Loss at epoch 10: 0.134810, lr: 0.01000
#> Loss at epoch 11: 0.271304, lr: 0.01000
#> Loss at epoch 12: 0.163670, lr: 0.01000
#> Loss at epoch 13: 0.154902, lr: 0.01000
#> Loss at epoch 14: 0.138467, lr: 0.01000
#> Loss at epoch 15: 0.129389, lr: 0.01000
#> Loss at epoch 16: 0.148871, lr: 0.01000
#> Loss at epoch 17: 0.122617, lr: 0.01000
#> Loss at epoch 18: 0.132185, lr: 0.01000
#> Loss at epoch 19: 0.265274, lr: 0.01000
#> Loss at epoch 20: 0.135628, lr: 0.01000
#> Loss at epoch 21: 0.130431, lr: 0.01000
#> Loss at epoch 22: 0.223102, lr: 0.01000
#> Loss at epoch 23: 0.153003, lr: 0.01000
#> Loss at epoch 24: 0.181313, lr: 0.01000
#> Loss at epoch 25: 0.133016, lr: 0.01000
#> Loss at epoch 26: 0.190124, lr: 0.01000
#> Loss at epoch 27: 0.117535, lr: 0.01000
#> Loss at epoch 28: 0.162225, lr: 0.01000
#> Loss at epoch 29: 0.179409, lr: 0.01000
#> Loss at epoch 30: 0.175460, lr: 0.01000
#> Loss at epoch 31: 0.172634, lr: 0.01000
#> Loss at epoch 32: 0.121435, lr: 0.01000
#> Loss at epoch 33: 0.115251, lr: 0.01000
#> Loss at epoch 34: 0.166737, lr: 0.01000
#> Loss at epoch 35: 0.151699, lr: 0.01000
#> Loss at epoch 36: 0.166549, lr: 0.01000
#> Loss at epoch 37: 0.192639, lr: 0.01000
#> Loss at epoch 38: 0.305669, lr: 0.01000
#> Loss at epoch 39: 0.147130, lr: 0.01000
#> Loss at epoch 40: 0.195244, lr: 0.01000
#> Loss at epoch 41: 0.108696, lr: 0.01000
#> Loss at epoch 42: 0.127913, lr: 0.01000
#> Loss at epoch 43: 0.266621, lr: 0.01000
#> Loss at epoch 44: 0.128631, lr: 0.01000
#> Loss at epoch 45: 0.113665, lr: 0.01000
#> Loss at epoch 46: 0.113005, lr: 0.01000
#> Loss at epoch 47: 0.180654, lr: 0.01000
#> Loss at epoch 48: 0.190955, lr: 0.01000
#> Loss at epoch 49: 0.141816, lr: 0.01000
#> Loss at epoch 50: 0.129946, lr: 0.01000
#> Loss at epoch 51: 0.129010, lr: 0.01000
#> Loss at epoch 52: 0.134041, lr: 0.01000
#> Loss at epoch 53: 0.175009, lr: 0.01000
#> Loss at epoch 54: 0.137302, lr: 0.01000
#> Loss at epoch 55: 0.361235, lr: 0.01000
#> Loss at epoch 56: 0.116260, lr: 0.01000
#> Loss at epoch 57: 0.169096, lr: 0.01000
#> Loss at epoch 58: 0.114080, lr: 0.01000
#> Loss at epoch 59: 0.127167, lr: 0.01000
#> Loss at epoch 60: 0.118832, lr: 0.01000
#> Loss at epoch 61: 0.166644, lr: 0.01000
#> Loss at epoch 62: 0.106772, lr: 0.01000
#> Loss at epoch 63: 0.146594, lr: 0.01000
#> Loss at epoch 64: 0.119910, lr: 0.01000
#> Loss at epoch 65: 0.122333, lr: 0.01000
#> Loss at epoch 66: 0.107494, lr: 0.01000
#> Loss at epoch 67: 0.149351, lr: 0.01000
#> Loss at epoch 68: 0.206519, lr: 0.01000
#> Loss at epoch 69: 0.117536, lr: 0.01000
#> Loss at epoch 70: 0.140394, lr: 0.01000
#> Loss at epoch 71: 0.129999, lr: 0.01000
#> Loss at epoch 72: 0.112676, lr: 0.01000
#> Loss at epoch 73: 0.123784, lr: 0.01000
#> Loss at epoch 74: 0.108112, lr: 0.01000
#> Loss at epoch 75: 0.112921, lr: 0.01000
#> Loss at epoch 76: 0.107853, lr: 0.01000
#> Loss at epoch 77: 0.150079, lr: 0.01000
#> Loss at epoch 78: 0.104745, lr: 0.01000
#> Loss at epoch 79: 0.114375, lr: 0.01000
#> Loss at epoch 80: 0.163115, lr: 0.01000
#> Loss at epoch 81: 0.161906, lr: 0.01000
#> Loss at epoch 82: 0.165628, lr: 0.01000
#> Loss at epoch 83: 0.123785, lr: 0.01000
#> Loss at epoch 84: 0.113272, lr: 0.01000
#> Loss at epoch 85: 0.154188, lr: 0.01000
#> Loss at epoch 86: 0.264724, lr: 0.01000
#> Loss at epoch 87: 0.149808, lr: 0.01000
#> Loss at epoch 88: 0.126189, lr: 0.01000
#> Loss at epoch 89: 0.147067, lr: 0.01000
#> Loss at epoch 90: 0.141372, lr: 0.01000
#> Loss at epoch 91: 0.139103, lr: 0.01000
#> Loss at epoch 92: 0.123927, lr: 0.01000
#> Loss at epoch 93: 0.131540, lr: 0.01000
#> Loss at epoch 94: 0.127167, lr: 0.01000
#> Loss at epoch 95: 0.113796, lr: 0.01000
#> Loss at epoch 96: 0.115746, lr: 0.01000
#> Loss at epoch 97: 0.106647, lr: 0.01000
#> Loss at epoch 98: 0.147512, lr: 0.01000
#> Loss at epoch 99: 0.155161, lr: 0.01000
#> Loss at epoch 100: 0.147167, lr: 0.01000
#> Number of Neighborhoods reduced to 8
# }