# model_parts

##### Dataset Level Variable Importance as Change in Loss Function after Variable Permutations

From DALEX version 1.0 this function calls the `feature_importance`

Find information how to use this function here: https://pbiecek.github.io/ema/featureImportance.html.

##### Usage

```
model_parts(
explainer,
loss_function = loss_sum_of_squares,
...,
type = "variable_importance",
n_sample = 1000
)
```

##### Arguments

- explainer
a model to be explained, preprocessed by the

`explain`

function- loss_function
a function that will be used to assess variable importance

- ...
other parameters

- type
character, type of transformation that should be applied for dropout loss.

`variable_importance`

and`raw`

results raw drop lossess,`ratio`

returns`drop_loss/drop_loss_full_model`

while`difference`

returns`drop_loss - drop_loss_full_model`

- n_sample
number of observations that should be sampled for calculation of variable importance. If negative then variable importance will be calculated on whole dataset (no sampling).

##### Value

An object of the class `feature_importance`

.
It's a data frame with calculated average response.

##### References

Explanatory Model Analysis. Explore, Explain and Examine Predictive Models. https://pbiecek.github.io/ema/

##### Examples

```
# NOT RUN {
# }
# NOT RUN {
library("ranger")
titanic_ranger_model <- ranger(survived~., data = titanic_imputed, num.trees = 50,
probability = TRUE)
explainer_ranger <- explain(titanic_ranger_model, data = titanic_imputed[,-8],
y = titanic_imputed$survived)
vi_ranger <- model_parts(explainer_ranger, type = "raw")
head(vi_ranger, 8)
plot(vi_ranger)
titanic_glm_model <- glm(survived~., data = titanic_imputed, family = "binomial")
explainer_glm <- explain(titanic_glm_model, data = titanic_imputed[,-8],
y = titanic_imputed$survived)
logit <- function(x) exp(x)/(1+exp(x))
vi_glm <- model_parts(explainer_glm, type = "raw",
loss_function = function(observed, predicted)
sum((observed - logit(predicted))^2))
head(vi_glm, 8)
plot(vi_glm)
# }
# NOT RUN {
# }
```

*Documentation reproduced from package DALEX, version 1.2.1, License: GPL*