Exam in Statistical Machine Learning Statistisk Maskininlärning (1RT700)
Exam in Statistical Machine Learning Statistisk Maskininlärning (1RT700)
Exam in Statistical Machine Learning Statistisk Maskininlärning (1RT700)
Number of problems: 5
• For subproblems (a), (b), (c), . . . , it is usually possible to answer later subproblems
independently of the earlier subproblems (for example, you can answer (b) without
answering (a)).
With the exception of Problem 1, all your answers must be clearly motivated!
A correct answer without a proper motivation will score zero points!
Good luck!
Some relevant formulas
Pages 1–3 contain some expressions that may or may not be useful for solving the exam
problems. This is not a complete list of formulas used in the course, but some of the
problems may require knowledge about certain expressions not listed here. Furthermore,
the formulas listed below are not self-explanatory, meaning that you need to be familiar
with the expressions to be able to interpret them. They are possibly a support for solving
the problems, but not a comprehensive summary of the course.
1
where log `(β) = ni=1 log p(yi | xi ; β) is the log-likelihood function (the last equality
P
holds when the n training data points are modeled to be independent).
Logistic regression: The logistic regression combines linear regression with the logistic
function to model the class probability
T
eβ x
p(y = 1 | x) = T .
1 + eβ x
For multi-class logistic regression we use the softmax function and model
T
eβk xi
p(y = k | xi ) = PK T
.
l=1 eβl xi
where
bk = nk /n for k = 1, . . . , K
π
1 X
µ
bk = xi for k = 1, . . . , K
nk i:y =k
i
K
1 X X
Σ
b = (xi − µ b k )T .
b k )(xi − µ
n − K k=1 i:y =k
i
where µ
b k and π
bk are as for LDA, and
1 X
Σ
bk = (xi − µ b k )T .
b k )(xi − µ
n − 1 i:y =k
i
2
P|T |
Classification trees: The cost function for tree splitting is m=1 nm Qm where T is the
tree, |T | the number of terminal nodes, nm the number of training data points falling in
node m, and Qm the impurity of node m. Three common impurity measures for splitting
classification trees are:
where π 1
P
bmk = nm i:xi ∈Rm I(yi = k)
Loss functions for classification: For a binary classifier expressed as yb(x) = sign{C(x)},
for some real-valued function C(x), the margin is defined as y · C(x) (note the conven-
tion y ∈ {−1, 1} here). A few common loss functions expressed in terms of the margin,
L(y, C(x)) are,
otherwise.
0
(
1 for yc < 0,
Misclassification loss: L(y, c) =
0 otherwise.
3
1. This problem is composed of 10 true-or-false statements. You only have to classify
these as either true or false. For this problem (only!) no motivation is required.
Each correct answer scores 1 point, each incorrect answer scores -1 point and each
missing answer scores 0 points. The total score for the whole problem is capped
below at 0.
(10p)
4
2. Consider the following training data
i x y
x1 x2
1 0.0 5.0 1
2 4.0 1.0 0
3 1.0 2.0 1
4 4.0 2.0 0
5 0.0 3.0 1
6 1.0 8.0 1
7 9.0 0.0 0
8 6.0 5.0 0
9 8.0 6.0 0
10 5.0 7.0 1
where x is the two-dimensional input variable, y the output and i is the data point
index.
(a) Illustrate the training data points in a graph with x1 and x2 on the two axes.
Represent the points belonging to class 0 with a cross and those belonging to
class 1 with a circle. Also annotate the data points with their data point indices.
(1p)
(b) Based on the training data we want to construct a random forest classifier with
B = 3 trees, each of depth one (i.e., stumps). For this we randomly draw 3 new
datasets by bootstrapping the training data (sampling with replacement). We also
randomly draw an input dimension index (1 or 2), along which the split is to be
performed (if the split dimension is 1, the split is on the form x1 < c, etc). The
following data points indices have been drawn for each of the three bootstrapped
datasets:
Data point indices i Split dimension
Dataset 1 1 2 4 4 6 7 8 9 9 10 Tree 1 2
Dataset 2 1 2 3 4 5 5 6 7 7 9 Tree 2 2
Dataset 3 1 1 4 5 5 5 6 9 9 9 Tree 3 1
For each bootstrapped dataset, construct a classification stump (tree of depth one)
by finding the split among the prescribed dimension which minimizes the Gini
index.
(5p)
(c) The final random forest classifier predicts according to a majority vote of the three
trees. Sketch the decision boundary of the final classifier.
(4p)
5
3. (a) Why is the training error not a good estimate of the test error? Explain in a few
sentences.
(3p)
(b) What is the purpose of using cross-validation? Explain in a few sentences.
(3p)
(c) For each of the following decision boundaries (1, 2, 3 and 4), tell whether it could
possibly come from one of these classifiers
• logistic regression
• LDA
• QDA
• k-NN with k = 3
• A decision tree of depth 2
• A random forest with B = 3 trees, each of maximum depth 3
It is assumed that each classifier only uses x1 and x2 as inputs, and no nonlinear
transformations of them.
Note! Each decision boundary could possibly origin from more than one classifier.
Do not forget to include a motivation for all your answers.
(4p)
6
4. (a) Consider the following training data
i x y
x1 x2
1 −1 2 2
2 0 0 1
3 1 −2 −3
from which we want to learn a linear regression model
y = β0 + β1 x1 + β2 x2 + ε,
7
We have after the exam realized that the inverse in H(γ) was missing in the actual
exam. We will take this typo into consideration in the grading.
5. For leave-one-out cross validation (or equivalently c-fold cross validation with
c = n) the cross validation error Eval for ridge regression actually has a closed-
form solution
n 2
1X ŷi − yi
Eval = , (1)
n i=1 1 − [H(γ)]ii
where ŷi is the prediction of yi when the model is learned from all n data points
(no data point is left out), γ the regularization parameter and [H(γ)]ii is element
(i, i) of the matrix H(γ) = X(XT X + γI)−1 XT .
In this problem, we will let xTi denote the entire ith row of X.
(a) Let X−i denote the matrix X where row i is removed, and y−i is the column
vector y with element i removed. Show that
XT−i X−i = XT X − xi xTi ,
XT−i y−i = XT y − xi yi , and
[H(γ)]ii = xTi (XT X + γI)−1 xi
(1p)
(b) Using the results from (a) and a special case of the matrix inversion lemma
A−1 vvT A−1
(A − vvT )−1 = A−1 + ,
1 − vT A−1 v
show that
1
β
b =β
−i
b+ (XT X + γI)−1 xi (ŷi − yi ).
1 − [H(γ)]ii
Here βb are the parameters learned from all data points except i, and β
−i
b the
parameters learned from all data.
Hint: Start from the ridge regression expression for β b as a function of X−i , y
−i −i
and γ.
(4p)
(c) Use your result from (b) to derive eq. (1), starting from
n 2
1 X bT
Eval = β −i xi − yi .
n i=1
(2p)
(d) Describe (in a few sentences) what eq. (1) can be used for in practice.
(3p)