Question: Using an example of kNN ( k - Nearest Neighbors ) model used for predicting concentration of nitrogen oxides ( NOx ) in Boston air,
Using an example of kNN kNearest Neighbors model used for predicting concentration of nitrogen oxides NOx in Boston air, based on a single predictor weighted average distance from employment centers in Boston area. In this question you are going to tune the hyperparameter ie find its optimal value, and then fit the model with that value of But first, you will produce the following plot from class, which shows how performance of the fitted model varies with the change of the tuning parameter We will use simple validation and split the data into train and test subsets. To simplify, we first extract the two variables nox and dist from Boston data frame from MASS library, and create a new data frame called df To do that, run the following cell. Create data frames train and test from the data frame df The data frame train should consist of observations ie rows of df whose indices are precisely those random indices from vector tr The data frame test should consist of the complement of tr you can use dftr for taking the complementary indices, ie precisely those indices which are not in tr
Hint: First two rows of train should be
xall yall
and of test:
xall yall
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
