Interpretable Machine Learning
Interpretable Machine Learning
AUTHOR PUBLISHED
Munir Eberhardt Hiabu March 19, 2024
library(mlr3)
library(mlr3learners )
library(mlr3tuning)
library(mlr3mbo)
library(glmnet)
library(OpenML)
library(mlr3pipelines)
https://mhiabu.github.io/iml_aims/assignment1.html Page 1 of 7
Interpretable Machine Learning 20/03/2024, 8:34 in the evening
Train your model on the training set and evaluate it on the test set.
s = to_tune(0, 1)
alpha = to_tune(0, 1)
graph_learner_elastic_net$param_set$values =
instance$result_learner_param_vals
graph_learner_elastic_net$param_set$values$classif.glmnet.la
mbda =
graph_learner_elastic_net$param_set$values$classif.glmnet.s
https://mhiabu.github.io/iml_aims/assignment1.html Page 2 of 7
Interpretable Machine Learning 20/03/2024, 8:34 in the evening
graph_learner_elastic_net$model$classif.glmnet$model$beta
Part 2 (Frisch–Waugh–Lovell
theorem)
In this part we will study the Frisch–Waugh–Lovell theorem. The implied
algorithm, but using machine learning instead of linear regression, has been
introduced a couple of years ago as Double Machine Learning. Since then it has
gained a lot of attention and popularity. Here, we want to verify the result via a
coding exercise.
library(mlr3)
library(mlr3learners)
library(OpenML)
library(mlr3pipelines)
:::
https://mhiabu.github.io/iml_aims/assignment1.html Page 3 of 7
Interpretable Machine Learning 20/03/2024, 8:34 in the evening
a. Run simple least squares linear regression with response being count and
predictor equal windspeed . Report the coefficient you get.
b. Run least squares linear regression with response being count and predictor
being all remaining variables. Don’t forget to create a graph to dummy-
encode the factor variables. Report the coefficient you get for windspeed .
Run least squares linear regression with response being count and predictor
being all remaining variables except windspeed . Calculate the residuals and
call that variable count_residuals .
Run least squares linear regression with response being windspeed and
predictor being all remaining variables except count . Calculate the residuals
and call that variable windpseed_residuals .
Run simple least squares linear regression with response being
count_residuals and predictor windpseed_residuals .
Report the regression coefficient you get.
d. Verify that the coefficients in Steps (b) and (c) are the same.
e. Replace the simple linear regression model in the second last step in part (c)
by an auto-tuned k-nearest neighbors. Visualize the fit (by plotting
windpseed_residuals against observed and predicted
count_residuals ) and compare it to the previous simple linear regression
fit. Discuss the result.
library(mlr3)
library(mlr3learners)
library(mlr3tuning)
library(OpenML)
library(mlr3pipelines)
library(future)
future::plan("multisession")
https://mhiabu.github.io/iml_aims/assignment1.html Page 4 of 7
Interpretable Machine Learning 20/03/2024, 8:34 in the evening
(a)
Use the learner classif.rpart with predict_type = "prob" and train it on
the task. Visualize the learned tree via
(b)
We now aim to find a penalty parameter α that results in a pruned tree with
strong predictive power. To this end, we define a tree learner that runs the
weakest link algorithm and therea"er 5-fold cross validation to compare the
performance between different trees.
You can run the following command on the rpart object in order to see the CV
result. Hint: If unsure how to extract the rpart object from your trained graph,
check how this was done in part (a) above.
(c)
Pick an α that is big enough and also has a low error. In the rpart package
vignette, the following advice is given:
Train and then visualize the tree with the chosen α. (The relevant parameter is
called cp ).
https://mhiabu.github.io/iml_aims/assignment1.html Page 5 of 7
Interpretable Machine Learning 20/03/2024, 8:34 in the evening
(d)
Using the benchmark function, compare the predictive performance of the
following five algorithms
You may want too look at more then just the classification error. You can for
example run.
Remark
Note that we are not comparing how an optimally pruned decision tree compares to
other algorithms that are optimally tuned. While this is possible (one would just need to
decide on how to choose the optimal α explicitly and define an auto-tuner accordingly),
the purpose of this task is another. While we expect that a single decision tree will have
poorer performance than tree ensembles, we would like to know how big the
performance loss is if we choose to employ an interpretable decision tree. Here it is also
essential that the α we have chosen in (c) is big enough such that it leads to a small
enough tree.
(e)
The German Credit dataset comes with a cost matrix
https://www.openml.org/search?type=data&id=31&sort=runs&status=active.
https://mhiabu.github.io/iml_aims/assignment1.html Page 6 of 7
Interpretable Machine Learning 20/03/2024, 8:34 in the evening
Good (actual) 0 1
Bad (actual) 5 0
(f)
If time allows you can re-run part (d) where the auto-tuned object are optimized
via the measure defined in part (e) and see how much the results change.
https://mhiabu.github.io/iml_aims/assignment1.html Page 7 of 7