Exercises the coming week
Week 19
Exam 2021: Problems 1, 2 and 3.
Modified version of extra exercise 10: The purpose in this exercise is to reproduce Figures 8.6 and 8.8 of ISLR. The data set to be used in the analysis is the Heart data, store in the file Heart.csv in the data folder of the course. Here are the modified exercises:
a) Do as written in the exercise.
b) Reproduce Figure 8.6 of ISLR, but use r-code-week11.R from the lecture on March 25 as inspiration.
c) Do as written in the exercise, but to get the black curve, use mtry=p (i.e. do splits based on all covariates).
d) Do as written in the exercise, and additionally, you may also use r-code-week14.R from the lecture on April 9 as inspiration.
e) Add addtional curves to the plot, by also fitting gradient boosted trees, with possibly different tree sizes, using r-code-week13.R from the lecture on April 8 as inspiration. Here, you only need to compute the test error.
Exercises for past weeks
Week 18
Exercises from the book: 9.6 (in b only fit a tree). The ozone data are available here with some info here
- Solutions: esl_9_6.r
Exercises from ISLR: Exercise 8.4, 8.8a-c,e
- Solutions: islr_8_4.pdf and code examples in Chapter 8.3 Lab: Decision Trees in ISLR or https://rpubs.com/ppaquay/65564 (In 8.8b, use "
text(tree_model, pretty = 0, cex = 0.7)"
for a nicer plot).
Exam 2019: Problem 2.
Week 15
Extra exercises 12 and 13. You find the zip_nn.R file with examples on the use of nnet() and mlp() on the 2022 page: /studier/emner/matnat/math/STK2100/v22/r-scripts/.
- Solutions: extra_12.r and extra_13.r.
Week 14
Exam STK2100 2019: Exercises 1a,d,e and 3
Exam STK2100 2022: Exercise 1 (in d you do not need to consider the three last methods in the table)
- Solutions: /studier/emner/matnat/math/STK2100/oppgaver
Week 13
Exercises from the book: 5.4 and 5.7
- Solutions: this solution manual, and/or Vera's notes: esl_5_4.pdf esl_5_7.pdf.
Exercises from ISLR: Exercise 7.1, 7.9
- Solutions: https://rpubs.com/lmorgan95/ISLR_CH7_Solutions. Note that there are some similarities between ISLR 7.1 and ESL Ex. 5.1 from week 11 and R-code-examples in ISLR Ch. 7.8 Lab: Non-linear Modeling.
Extra exercise 7
- Solutions: Vinnie's solution, pp. 22-27.
Week 11
Exercises from the book: 4.2 and 5.1
- Solutions: See this solution manual, on which Vera's notes from 2024 is based (esl_4_2a.pdf, esl_5_1.pdf).
Exercises from ISLR: 4.9 and 4.14 (a-f)
- Solutions: islr2_4_9.pdf and Chapter 4.7 Lab: Classification Methods in the ISLR book for R-code-examples similar to 4.14.
Exam STK2100 2018: Problem 2
- Solution: /studier/emner/matnat/math/STK2100/oppgaver/STK2100_2018_fasit.pdf (in Norwegian).
Extra exercise 6
- Solutions: See Vera's solution, or Lars' solution from 2021.
Week 10
Exercises from the book: 4.1
- Solutions: Vera's notes, based on this solution manual.
Exercise from ISLR: 4.13 (without KNN)
- Solutions: islr2_4_13.r
Extra exercise: Modify the example with principal component (PC) regression in the R script r-code-week7.R, so that the numbers of principal components are selected through cross-validation instead of through separate training and test sets. Comment on the results.
- Solutions: r-code-week7-with-cv-for-pcr.r
Week 9
Exercises from the book: 3.2 and 3.29
- Solutions: esl_3_2.r (a simplified version of Lars' script from Spring 2023) and esl_3_29.pdf. More rigorous discussions are given in this solution manual (from page 33 and 57 for Exercise 3.2 and 3.29, respectively).
Exercises from ISLR: 3.9 a)-c) and e)-f)
- Solutions: rpubs.com/lmorgan95/ISLR_CH3_Solutions
Week 8
Exercises from ISLR: 3.3. 3.4, 3.6, and 3.7
- Solutions: rpubs.com/lmorgan95/ISLR_CH3_Solutions
Extra exercises 4 and 5 (extra4.r, advertising.r)
- Solutions: See Vinni's solutions and extra4_extended.r.
Week 6
Exercises from ISLR: 3.8 and 3.5
- Solutions: See Vinni's solutions, this one or that one.
Extra exercises (see link above): 1, 2 and 3
- Solutions: See Vinni's solutions, except from 2d, for which Vera presented this solution (where the lower bound is simply \(\sigma^2\), attained when \(f(x) = g(x)\)). For exercise 1, there are also Geir's solutions (excluding the R-part).
Week 5
Exercises from the book: 2.7
- Solutions: See pages 8-9 in /studier/emner/matnat/math/STK2100/v23/Exercise%20solutions/esl_ch2ex.pdf (note a typo in (a) for linear regression, where $\hat\beta$ should be $(X^TX)^{-1}X^Ty$ not $X(X^TX)^{-1}X^Ty$)).
Exercises from ISLR: 2.1, 2.2, and 2.8 (see the webpage for the book for downloading data; the easiest alternative is to install the ISLR library (through the command install.packages("ISLR")), make the library available (through the library("ISLR")), and then make the data available through data(College))
- Solutions: link to R-file.