Exercises
Exercises
Conceptual
Exercise 1 Conceptual
We fit a regression tree to the data \((x, y) = (1, 2), (2, 3), (3, 9), (4, 10), (5, 11)\).
- Compute the reduction in the sum of squares for every possible first split.
- Which split does the greedy algorithm take.
- Draw the tree of depth 2 and give the predicted value in each leaf.
Exercise 2 Conceptual
Explain in two sentences each.
- Why does a random forest not overfit when we add more trees, while gradient boosting does.
- Why does a random forest consider only a random subset of the predictors at each split.
- Why is a single deep tree a high variance method.
Exercise 3 Conceptual
Consider a support vector machine with a linear kernel.
- What happens to the solution if we move a point that is far from the boundary.
- What happens if we move a support vector.
- Compare this to linear regression, where every point influences the fit. Which behaviour do you want when the data contains outliers.
- Describe how the margin and the number of support vectors change as \(C\) goes from very small to very large.
Exercise 4 Conceptual
For each data set below, say which of the four methods you would try first and why.
- 500 rows, 10 predictors, mostly categorical, and the client wants to know which predictor matters.
- 200 rows, 20000 predictors, two classes.
- Two million rows, 30 numeric predictors.
- 60000 images of 28 by 28 pixels.
Applied
Exercise 5 Applied
Repeat the comparison from the comparison page on the weather data from week 2.
- Cross-validate all five methods on the training set and report the RMSE with the spread across folds.
- Which methods are indistinguishable on this data.
- Score the winner once on the 2019 to 2020 test set.
- Plot the variable importance of the random forest. Does it agree with the coefficients of the linear model.
Exercise 6 Applied
Tune gradient boosting properly.
- Cross-validate over the number of trees, the learning rate and the maximum depth, on a grid.
- Plot the cross-validated error against the number of trees, one line per learning rate. What is the relationship between the two.
- How much better is the tuned model than the default one.
- How much of that improvement survives when you score on a held-out test set.
Exercise 7 Applied · optional
Compare kernels for a support vector machine on the MNIST digits, using only the classes 3 and 8 and the first 2000 rows.
- Fit with a linear kernel and with an RBF kernel, tuning \(C\) and \(\gamma\).
- Report the test accuracy of both.
- How many support vectors does each one use, and what does that tell you.