Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
MSBA7027 Machine Learning
Homework 1
Notes:
- You are required to submit 1) original R Markdown file and 2) a knitted HTML or PDF file via
Moodle. Please provide comments for R code wherever you see appropriate. In general, be as
concise as possible while giving a fully complete answer. Nice formatting of the assignment will
receive extra points.
- Remember that the Class Policy strictly applies to homework. You are encouraged to work in
groups and discuss with fellow students. However, each student has to know how to answer the
questions on her/his own.
- Degree of freedom in this homework refers to degree of freedom in R.
Question 1. This question uses the variables horsepower and mpg from the Auto data as part of
the ISLR package. We will treat horsepower as the predictor and mpg as the response.
(a) Use the poly() function to fit a cubic polynomial regression to predict mpg using
horsepower. Report the regression output, and plot the resulting data and polynomial
fits.
(b) Use the bs() function to fit a cubic spline to predict mpg using horsepower. Report the
output for the fit using six degrees of freedom. How did you choose the knots? Plot the
resulting fit.
(c) Now fit a cubic spline for degrees of freedom ranging from 4 to 12, and plot the resulting fits
as well as the resulting RSS. Describe the results obtained.
(d) Perform cross-validation to select the best degrees of freedom for a cubic spline on this data.
Describe your results.
(e) Use the ns() function to fit a natural cubic spline to predict mpg using horsepower.
Report the output for the fit using degrees of freedom s.t. number of knots is the same as
(b). Plot the resulting fit.
(f) Now fit a natural cubic spline for a range of degrees of freedom, and plot the resulting fits as
well as the resulting RSS. Describe the results obtained.
(g) Perform cross-validation to select the best degrees of freedom for a natural cubic spline on
this data. Describe your results.
(h) Compare your results of (d) and (g), choose the best model for cubic spline and natural
cubic spline respectively. Which one performs the best? With how many knots?