10-701/15-781 Machine Learning - Midterm Exam, Fall 2010: Aarti Singh Carnegie Mellon University
10-701/15-781 Machine Learning - Midterm Exam, Fall 2010: Aarti Singh Carnegie Mellon University
Aarti Singh
Carnegie Mellon University
1. Personal info:
• Name:
• Andrew account:
• E-mail address:
2. There should be 15 numbered pages in this exam (including this cover sheet).
3. You can use any material you brought: any book, class notes, your print outs of
class materials that are on the class website, including annotated slides and relevant
readings, and Andrew Moore’s tutorials. You cannot use materials brought by other
students. Calculators are not necessary. Laptops, PDAs, phones and Internet access
are not allowed.
4. If you need more room to work out your answer to a question, use the back of the page
and clearly mark on the front of the page if we are to look at what’s on the back.
5. Work efficiently. Some questions are easier, some more difficult. Be sure to give yourself
time to answer all of the easy ones, and avoid getting bogged down in the more difficult
ones before you have answered the easier ones.
7. Good luck!
1
1 Short Questions [20 pts]
Are the following statements True/False? Explain your reasoning in only 1
sentence.
1. Density estimation (using say, the kernel density estimator) can be used to perform
classification.
True: Estimate the joint density P (Y, X), then use it to calculate P (Y |X).
2. The correspondence between logistic regression and Gaussian Naı̈ve Bayes (with iden-
tity class covariances) means that there is a one-to-one correspondence between the
parameters of the two classifiers.
False: Each LR model parameter corresponds to a whole set of possible GNB classifier
parameters, there is no one-to-one correspondence because logistic regression is discrimi-
native and therefore doesn’t model P (X), while GNB does model P (X).
4. As the number of data points grows to infinity, the MAP estimate approaches the MLE
estimate for all possible priors. In other words, given enough data, the choice of prior
is irrelevant.
False: A simple counterexample is the prior which assigns probability 1 to a single choice
of parameter θ.
5. Cross validation can be used to select the number of iterations in boosting; this pro-
cedure may help reduce overfitting.
True: The number of iterations in boosting controls the complexity of the model, therefore,
a model selection procedure like cross validation can be used to select the appropriate
model complexity and reduce the possibility of overfitting.
6. The kernel density estimator is equivalent to performing kernel regression with the
value Yi = n1 at each point Xi in the original data set.
False: Kernel regression predicts the value of a point as the weighted average of the values
at nearby points, therefore if all of the points have the same value, then kernel regression
will predict a constant (in this case, n1 ) for all values.
2
8. The depth of a learned decision tree can be larger than the number of training examples
used to create the tree.
False: Each split of the tree must correspond to at least one training example, therefore, if
there are n training examples, a path in the tree can have length at most n.
Note: There is a pathological situation in which the depth of a learned decision tree can be
larger than number of training examples n - if the number of features is larger than n and
there exist training examples which have same feature values but different labels. Points
have been given if you answered true and provided this explanation.
Circle all of the classifiers that will achieve zero training error on this data set. (You
may circle more than one.)
3
2. For the following dataset, circle the classifier which has larger Leave-One-Out Cross-
validation error.
a) 1-NN
b) 3-NN
4
2 Bayes Optimal Classification [15 pts]
In classification, the loss function we usually want to minimize is the 0/1 loss:
1. [4 pts] Determine the Bayes optimal classifier, i.e. the classifier that achieves minimum
risk assuming P (x, y) is known, for the loss `α,β where α, β > 0.
Solution: We can write
arg min E`α,β (f (x), y) = arg min EX,Y [α1{f (X) = 1, Y = 0} + β1{f (X) = 0, Y = 1}]
f f
= arg min EX [EY |X [α1{f (X) = 1, Y = 0} + β1{f (X) = 0, Y = 1}]]
f
Z
= arg min EX [ α1{f (X) = 1, y = 0} + β1{f (X) = 0, y = 1}dP (y|x)]
f y
Z
= arg min [α1{f (x) = 1}P (y = 0|x) + β1{f (x) = 0}P (y = 1|x)]dP (x)
f x
Show how this risk is equivalent to choosing a certain α, β and minimizing the risk
where the loss function is `α,β .
Solution: Notice that
E`α,β (f (x), y) = αP (f (x) = 1, y = 0) + βP (f (x) = 0, y = 1)
= αP (f (x) = 1|y = 0)P (y = 0) + βP (f (x) = 0|y = 1)P (y = 1)
1 1
which is same as the minimizer of the given risk R if α = P (y=0) and β = P (y=1) .
5
3. [4 pts] Consider the following classification problem. I first choose the label Y ∼
Bernoulli( 12 ), which is 1 with probability 21 . If Y = 1, then X ∼ Bernoulli(p); otherwise,
X ∼ Bernoulli(q). Assume that p > q. What is the Bayes optimal classifier, and what
is its risk?
Solution: Since label is equally likely to be 1 or 0, to minimize prob of error simply
predict the label for which feature value X is most likely. Since p > q, X = 1 is most
likely for Y = 1 and X = 0 is most likely for Y = 0. Hence f ∗ (X) = X. Baye’s risk
= P (X 6= Y ) = 1/2 · (1 − p) + 1/2 · q.
Formally: Notice that since Y ∼ Bernoulli( 21 ), we have P (Y = 1) = P (Y = 0) = 1/2.
4. [4 pts] Now consider the regular 0/1 loss `, and assume that P (y = 0) = P (y = 1) =
1/2. Also, assume that the class-conditional densities are Gaussian with mean µ0 and
co-variance Σ0 under class 0, and mean µ1 and co-variance Σ1 under class 1. Further,
assume that µ0 = µ1 .
For the following case, draw contours of the level sets of the class conditional densities
and label them with p(x|y = 0) and p(x|y = 1). Also, draw the decision boundaries
obtained using the Bayes optimal classifier in each case and indicate the regions where
the classifier will predict class 0 and where it will predict class 1.
10 40
Σ0 = , Σ1 =
04 01
6
Y= 0
Y= 1 Y= 1
Y= 0
7
3 Logistic Regression [18 pts]
We consider here a discriminative approach for solving the classification problem illustrated
in Figure 1.
Figure 1: The 2-dimensional labeled training set, where ‘+’ corresponds to class y=1 and
‘O’ corresponds to class y = 0.
1. We attempt to solve the binary classification task depicted in Figure 1 with the simple
linear logistic regression model
1
P (y = 1|~x, w)
~ = g(w0 + w1 x1 + w2 x2 ) = .
1 + exp(−w0 − w1 x1 − w2 x2 )
Notice that the training data can be separated with zero training error with a linear
separator.
Consider training regularized linear logistic regression models where we try to maximize
n
X
log (P (yi |xi , w0 , w1 , w2 )) − Cwj2
i=1
for very large C. The regularization penalties used in penalized conditional log-
likelihood estimation are −Cwj2 , where j = {0, 1, 2}. In other words, only one of the
parameters is regularized in each case. Given the training data in Figure 1, how does
the training error change with regularization of each parameter wj ? State whether the
training error increases or stays the same (zero) for each wj for very large C. Provide
a brief justification for each of your answers.
8
(a) By regularizing w2 [2 pts]
Consider again the problem in Figure 1 and the same linear logistic regression model
P (y = 1|~x, w)
~ = g(w0 + w1 x1 + w2 x2 ).
9
(b) [3 pts] For very large C, with the same L1-norm regularization for w1 and w2 as
above, which value(s) do you expect w0 to take? Explain briefly. (Note that the
number of points from each class is the same.) (You can give a range of values
for w0 if you deem necessary).
SOLUTION: For very large C, we argued that both w1 and w2 will go to zero. Note
that when w1 = w2 = 0, the log-probability of labels becomes a finite value, which is
equal to n log(0.5), i.e. w0 = 0. In other words, P (y = 1|~x, w)=P
~ (y = 0|~x, w)=0.5.
~ We
expect so because the number of elements in each class is the same and so we would
like to predict each one with the same probability, and w0 =0 makes P (y = 1|~x, w)=0.5.
~
(c) [3 pts] Assume that we obtain more data points from the ‘+’ class that corre-
sponds to y=1 so that the class labels become unbalanced. Again for very large
C, with the same L1-norm regularization for w1 and w2 as above, which value(s)
do you expect w0 to take? Explain briefly. (You can give a range of values for w0
if you deem necessary).
SOLUTION: For very large C, we argued that both w1 and w2 will go to zero. With
unbalanced classes where the number of ‘+’ labels are greater than that of ‘o’ labels,
we want to have P (y = 1|~x, w) ~ For that to happen the value of w0
~ > P (y = 0|~x, w).
should be greater than zero which makes P (y = 1|~x, w)
~ > 0.5.
10
4 Kernel regression [16 pts]
Now lets consider the non-parametric kernel regression setting. In this problem, you will
investigate univariate locally linear regression where the estimator is of the form:
fb(x) = β1 + β2 x
and the solution for parameter vector β = [β1 β2 ] is obtained by minimizing the weighted
least square error:
n Xi −x
X K
J(β1 , β2 ) = Wi (x)(Yi − β1 − β2 Xi )2 where Wi (x) = Pn h
Xi −x
,
i=1 i=1 K h
where K is a kernel with bandwidth h. Observe that the weighted least squares error can
be expressed in matrix form as
1 Xn
1. [4 pts] Derive an expression in matrix form for the solution vector β̂ that minimizes
the weighted least square.
Solution: Differentiating the objective function wrt β, we have:
∂J(β)
= 2AT W Aβ − 2AT W T Y.
β
AT W Aβ = AT W T Y
3. [3 pts] If the solution is not unique, one approach is to optimize the objective function
J using gradient descent. Write the update equation for gradient descent in this case.
Note: Your answer must be expressed in terms of the matrices defined above.
11
Solution: Let α > 0 denote the step-size.
α ∂J(β)
β (t+1) = β (t) −
2 ∂β
= β (t) − αAT W (Aβ − Y )
4. [3 pts] Can you identify the signal plus noise model under which maximizing the
likelihood (MLE) corresponds to the weighted least squares formulation mentioned
above?
iid
Solution: Y = β1 + β2 X + , where i ∼ N (0, σi2 ) for i = 1, . . . , n. Here σi2 ∝ 1/Wi (x).
5. [3 pts] Why is the above setting non-parametric? Mention one advantage and one
disadvantage of nonparametric techniques over parametric techniques.
Solution: The above setting is non-parametric since it performs locally linear fits, there-
fore number of parameters scale with data. Notice that Wi (x), and hence the solution β̂,
depends on x. Thus we are fitting the parameters to every point x - therefore total number
of parameters can be larger than n.
Nonparametric techniques do not place very strict assumptions on the form of the underlying
distribution or regression function, but are typically computationally expensive and require
large number of training examples.
12
5 SVM [16 pts]
5.1 L2 SVM
Let {(xi , yi )}li=1 be a set of l training pairs of feature vectors and labels. We consider binary
classification, and assume yi ∈ {−1, +1} ∀i. The following is the primal formulation of L2
SVM, a variant of the standard SVM obtained by squaring the hinge loss:
l
1 > CX 2
min w w+ ξ
w,b,ξ 2 2 i=1 i
s.t. yi (w> xi + b) ≥ 1 − ξi , i ∈ {1, . . . , l},
ξi ≥ 0, i ∈ {1, . . . , l}.
1. [4 pts] Show that removing the last set of constraints {ξi ≥ 0 ∀i} does not change the
optimal solution to the primal problem.
Solution: Let (w∗ , b∗ , ξ ∗ ) be the optimal solution to the problem without the last set of
constraints. It suffices to show that ξi∗ ≥ 0 ∀i. Suppose it is not the case, then there exists
some ξj∗ < 0. Then we have
implying that ξj0 = 0 is a feasible solution and yet gives a smaller objective value since
(ξj0 )2 = 0 < (ξj∗ )2 , a contradiction to the assumption that ξj∗ is optimal.
2. [3 pts] After removing the last set of constraints, we get a simpler problem:
l
1 > CX 2
min w w+ ξ
w,b,ξ 2 2 i=1 i (1)
s.t. yi (w> xi + b) ≥ 1 − ξi , i ∈ {1, . . . , l}.
3. [6 pts] Derive the dual of (1). How is it different from the dual of the standard SVM
with the hinge loss?
13
Solution: Taking partial derivatives of the Lagrangian wrt w, b and ξi ,
l
X
∇w L(w, b, ξ, α) = 0 ⇐⇒ w = αi yi xi ,
i=1
l
X
∂b L(w, b, ξ, α) = 0 ⇐⇒ αi yi = 0,
i=1
∂ξi L(w, b, ξ, α) = 0 ⇐⇒ ξi = αi /C .
Plugging these back to the Lagrangian, rearranging terms and keeping constraints on the
Lagrange multipliers we obtain the dual
1
max − α> (Q + I/C)α + 1> α
α 2
>
s.t. y α = 0, αi ≥ 0 ∀i,
where 1 is a vector of ones, I is the identity matrix, y is the vector of labels yi ’s, and Q is
the l-by-l kernel matrix such that Qij = yi yj x>
i xj . Compared with the dual of the standard
SVM, the quadratic term is regularized by an additional positive diagonal matrix, and thus
has stronger convexity leading to faster convergence. The other difference is that the dual
variables here are only bounded from below, but in the standard SVM the dual variables are
bounded both from above (by C) and from below. In fact, for L2 svms the solution does not
depend on the tradeoff parameter C.
14
6 Boosting [15 pts]
1. Consider training a boosting classifier using decision stumps on the following data set:
(a) [3 pts] Which examples will have their weights increased at the end of the first
iteration? Circle them.
Solution: The negative example since the decision stump with least error in first
iteration is constant over the whole domain. Notice this decision stump only predicts
incorrectly on the negative example, whereas any other decision stump predicts incor-
rectly on at least two training examples.
(b) [3 pts] How many iterations will it take to achieve zero training error? Explain.
Solution: At least three iterations. The first iteration misclassifies the negative ex-
ample, the second iteration misclassifies two of the positive examples as the negative
one has large weight. The third iteration is needed since a weighted sum of the first two
decision stumps can’t yield zero training error, and misclassifies the other two positive
examples. See Figures below.
+ + +
(c) [3 pts] Can you+add one more example to the training set so that+ boosting will
achieve zero training error in two steps? If not, explain why.
Solution: No. Notice that the simplest case is adding one more negative example
in center or one more positive example between any two positive examples, as it still
yields three decision regions with axis-aligned boundaries. If only two steps were
enough, then a linear combination of only two decision stumps sign(α1 h1 (x)+α2 h2 (x))
15
should be able to yield three decision regions. Also notice that at least one of h1 or h2
misclassifies two positive examples. If only h2 misclassifies two positive examples, the
possible decisions are (1) sign(α1 − α2 ) on those two positive examples, (2) sign(α1 +
α2 ) on the remaining positive examples and (3) sign(α1 −α2 ) on the negative examples
- which don’t yield zero training error since signs on (1) and (3) agree. If both h1 and h2
misclassify two positive examples, we have (1) sign(α1 −α2 ) on two positive examples,
(2) sign(−α1 + α2 ) on the remaining positive examples and (3) sign(−α1 − α2 ) on the
negative - which again don’t yield zero training error since signs on (1) and (2) don’t
agree.
3. [4 pts] Suppose AdaBoost is run on m training examples, and suppose on each round
that the weighted training error t of the tth weak hypothesis is at most 1/2 − γ, for
some number γ > 0. After how many iterations, T , will the combined hypothesis H
be consistent with the m training examples, i.e., achieves zero training error? Your
answer should only be expressed in terms of m and γ. (Hint: What is the training
error when 1 example is misclassified?)
Solution: Training error when 1 example is misclassified = 1/m. Therefore, we need to
guarantee that training error is < 1/m. Since t ≤ 1/2 − γ, from class notes we know that
16