Question: Use R code to complete the following 4 points] Consider again the zip code digits data. And we will use the Eucleadian distance. We want
Use R code to complete the following
![Use R code to complete the following 4 points] Consider again the](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66dbd3abbfee7_60366dbd3ab3d055.jpg)
4 points] Consider again the zip code digits data. And we will use the Eucleadian distance. We want to predict the digit of the 4th observation in the testing dataset library (ElemStatLearn) train.x zip.traint, -1] train.y -as.factor(zip.train[, 1]) test.x.one zip.test 14,-1 Do the following steps. Note that you cannot use any built-in kNN function for this entire question. For step1),you cannot use any for-loops. As a hint, you may consider using sweep and rowSums, while other functions can also get the job done. 1. Using covariates test.x.one find the indices of all 15 nearest neighbors in the training data. 2. Find the most frequent digit among these 15 observations. Is this the true digit of this testing data? 3. How about changing the value of k? Can we get a correct prediction? Apply steps 1 and 2 to the first 100 observations in the testing data, with k ranging from 1 to 20. Which k seems to perform the best? Use evidence to support your answer. 4 points] Consider again the zip code digits data. And we will use the Eucleadian distance. We want to predict the digit of the 4th observation in the testing dataset library (ElemStatLearn) train.x zip.traint, -1] train.y -as.factor(zip.train[, 1]) test.x.one zip.test 14,-1 Do the following steps. Note that you cannot use any built-in kNN function for this entire question. For step1),you cannot use any for-loops. As a hint, you may consider using sweep and rowSums, while other functions can also get the job done. 1. Using covariates test.x.one find the indices of all 15 nearest neighbors in the training data. 2. Find the most frequent digit among these 15 observations. Is this the true digit of this testing data? 3. How about changing the value of k? Can we get a correct prediction? Apply steps 1 and 2 to the first 100 observations in the testing data, with k ranging from 1 to 20. Which k seems to perform the best? Use evidence to support your
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
