Answered step by step
Verified Expert Solution
Link Copied!

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 df. The data frame train should consist of observations (i.e. rows) of df whose indices
are precisely those 400 random indices from vector tr. The data frame test should consist of the complement of tr(you can use df[-tr,] for
taking the complementary indices, i.e. precisely those indices which are not in tr).
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 (i.e. hyperparameter)k in the kNN model. We will take values 1,2,dots,350. We could
also include values up to the size of the training sample train (which is 400), but it's not difficult to see that the performance of the model for such
values of k would be lower than performance for all other values of k.
Apart from kvec, we also define nk to be the length of kvec (i.e.350). Run the following cell to create kvec and nk.
## run this code to create kvec and define nk
#loop over values of k, fit on train, predict on test
kvec =1:350
nk= length (kvec)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions