Question: R Program only: This question in R Programming Here we want to create a 5-NN classifier of the iris data. Following the discussion in class,

R Program only:

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. Answer all these questions.

(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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!