Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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