Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part ( b ) Create data frames train and test from the data frame d f . The data frame train should consist of observations
Part b
Create data frames train and test from the data frame The data frame train should consist of observations ie rows of whose indices
are precisely those random indices from vector The data frame test should consist of the complement of you can use dftr for
taking the complementary indices, ie precisely those indices which are not in
Hint: First two rows of train should be
## check whether train and test data are correct hidden tests
We now create vector kvec of possible values for the tuning parameter ie hyperparameter in the model. We will take values dots, We could
also include values up to the size of the training sample train which is but it's not difficult to see that the performance of the model for such
values of would be lower than performance for all other values of
Apart from kvec, we also define to be the length of kvec ie Run the following cell to create kvec and
## run this code to create kvec and define
#loop over values of fit on train, predict on test
kvec :
length
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started