Question: We will now perform cross - validation on a simulated dataset. ( a ) 4 p t s Generate a simulated dataset as follows: def

We will now perform cross-validation on a simulated dataset.
(a)4pts Generate a simulated dataset as follows:
def f(x):
return x**5-24+x***3
np.random.seed(1)
x = np.random.uniform(0,1, size=500)
y = f(x)+ np.random.normal (0,0.01, size=500)
(b)4pts Create a scatterplot of x against y. Comment on what you find. (Hint: You
may find plot() helpful)
(c)[4pts] Set a random seed 123, and then compute the LOOCV errors that result from
fitting the polynomial functions of degree from 1 to 7 using the simulated data in (a):
f1(x)=0+1x+
f2(x)=0+1x+2x2+
vdots
f7(x)=0+1x+2x2+3x3cdots+7x7+
(Hint: See Section 5.3 in ISLP for an example of how to implement cross-validation in
Python. You may find
from sklearn.model_selection import cross_validate
from ISLP.models import sklearn_sm
helpful )
(d)[4pts] Repeat (c) using another random seed 12345, and report your results. Are your
results the same as what you got in (c)? Why?
(e)[4pts] Which of the models in (c) had the smallest LOOCV error? Is this what you
expected? Explain your answer.
(f)[4pts] Fit f5(x) using least squares. Comment on the coefficient estimates and their
statistical significance.
We will now perform cross - validation on a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!