Question

gives the best training error rate?

Exercise 3. (50 points) For this exercise, the only extra package allowed is ISLR2. The

functions cut, glm, 1m, predict, spline and splinefun are not allowed in this exercise.

The dataset Auto will be used throughout the exercise and is accessible through the ISLR2

package. We are interested in using horsepower to predict mpg.

I. Consider some continuous random variable X and some probability p. The p-quantile

of X is defined as the value q such that

Pr{X

For example, the 0.5-quantile is called the median. The 0.25, 0.5 and 0.75-quantiles are

called the quartiles. The 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9-quantiles are called the

deciles etc...

The R function quantile gives an empirical estimate of some arbitrary random

variable's quantiles.

Building upon this knowledge, write an R function called findKnots that can be

applied to horsepower to get the following answers

• findKnots (horsepower,2) yields 93.5.

• findKnots (horsepower, 4) yields the three numbers 75.0, 93.5 and 126.0.

findKnots (horsepower, 10) yields the numbers 67.0, 72.0, 80.0, 88.0, 93.5.

100.0, 110.0, 140.0 and 157.7./nII. Write a function h1(x,xi) that takes a vector as first input argument and a single

number as a second input argument. When applied to a grid of points x (for a particular

value of xi), the R function yields a mathematical funciton whose plot is given by the

following figure:

.

"

Figure 4. The function h1

Reproduce the above figure. Describe the function mathematically and outline its

importance in statistical learning./nIII. Write an R function Linear Spline (x, b0, b1,b,xi) that is capable of generating figures

like the following ones.

.

Figure 5. Plot of LinearSpline (x, 3,-1,3,0)

Figure 6. Plot of LinearSpline (x,2,-4,c (2,3,2),c(-3,0,3))/n.

Figure 7. A third plot.

Reproduce each one of the three figures. Describe mathematically each of the func-

tions in each one of the figures. In the case of the third plot, describe how it is possible

to recover the function input arguments.

IV. Predict mpg by using a piecewise linear spline in horsepower at the knots 100 and 150,

and then reproduce the following figure:

110

Figure 8. A fit with two knots

Describe mathematically how the learning algorithm work while detailing each step.

What are the limitations and advantages of the such a model?/nDescribe mathematically how the learning algorithm work while detailing each step.

What are the limitations and advantages of the such a model?

V. Using the simple validation set approach where the car model year being 76 is used for

testing while all other car model years are used for training, choose the best model at

prediction among the following 10 models:

1. A linear regression.

2. A linear spline with a knot at the median of horsepower.

3.

10. A linear spline with knots at the deciles of horsepower.

Produce a figure that has the fit of all 10 models on it. How accurate do you think

the model selection is? What are the trade-offs?

VI. In case one wishes to extend the modeling strategy in the previous question to the case

one has two input variables, describe at least two alternative ways of carrying out that

extension. (write your answer using a maximum of 100 words)

Question image 1Question image 2Question image 3Question image 4Question image 5