Question
This question in R Programming Here we want to create a 5-NN classifier of the iris data. Following the discussion in class, for each instance
This question in R Programming
Here we want to create a 5-NN classifier of the iris data. Following the discussion in class, for each instance in
our data set we will find the 5 closest instances (other than the instance itself). It may help to know about the
order function in R: If x is vector of numbers, order(x) gives the order of elements. So if index=order(x) then
index[1] is the the index of the smallest element, index[2] is the index of the 2nd smallest, etc. Said another
way x[index[1]] is the smallest value of x, x[index[2]] is the 2nd smallest, etc. Use this information to create a
5-NN classifier for the iris data. That is, your classifier should loop through each row of the distance matrix
and tally the class labels of the 5 closest instances (other than the instance itself). You would classify the
instance according to the most prevalent class within the 5 neighbors, breaking ties arbitrarily.
(a) Compute a vector, classhat, which is the result of your classifier applied to each instance.
(b) Compute the error rate of your classifier.
(c) Explain why you do or dont believe your error rate is an accurate estimate of the generalization error
rate.
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