Get startedGet started for free

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:

Stop Sign Speed Limit Sign Pedestrian Sign

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

View Course

Exercise instructions

  • Classify the test_signs data using knn().
    • Set train equal to the observations in signs without labels.
    • Use test_signs for the test argument, again without labels.
    • For the cl argument, use the vector of labels provided for you.
  • Use table() to explore the classifier's performance at identifying the three sign types (the confusion matrix).
    • Create the vector signs_actual by extracting the labels from test_signs.
    • Pass the vector of predictions and the vector of actual signs to table() to cross tabulate them.
  • 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(___ == ___)
Edit and Run Code