Classifying a collection of road signs
Now that the autonomous vehicle has successfully stopped on its own, your team feels confident allowing the car to continue the test course.
The test course includes 59 additional road signs divided into three types:

At the conclusion of the trial, you are asked to measure the car's overall performance at recognizing these signs.
The class package and the dataset signs are already loaded in your workspace. So is the data frame test_signs, which holds a set of observations you'll test your model on.
This exercise is part of the course
Supervised Learning in R: Classification
Exercise instructions
- Classify the
test_signsdata usingknn().- Set
trainequal to the observations insignswithout labels. - Use
test_signsfor thetestargument, again without labels. - For the
clargument, use the vector of labels provided for you.
- Set
- Use
table()to explore the classifier's performance at identifying the three sign types (the confusion matrix).- Create the vector
signs_actualby extracting the labels fromtest_signs. - Pass the vector of predictions and the vector of actual signs to
table()to cross tabulate them.
- Create the vector
- Compute the overall accuracy of the kNN learner using the
mean()function.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Use kNN to identify the test road signs
sign_types <- signs$sign_type
signs_pred <- knn(train = ___[-1], test = ___[-1], cl = ___)
# Create a confusion matrix of the predicted versus actual values
signs_actual <- ___
table(___, ___)
# Compute the accuracy
mean(___ == ___)