MulaiMulai sekarang secara gratis

Seeing how the neighbors voted

When multiple nearest neighbors hold a vote, it can sometimes be useful to examine whether the voters were unanimous or widely separated.

For example, knowing more about the voters' confidence in the classification could allow an autonomous vehicle to use caution in the case there is any chance at all that a stop sign is ahead.

In this exercise, you will learn how to obtain the voting results from the knn() function.

The class package has already been loaded in your workspace along with the datasets signs, sign_types, and signs_test.

Latihan ini adalah bagian dari kursus

Supervised Learning in R: Classification

Lihat Kursus

Petunjuk latihan

  • Build a kNN model with the prob = TRUE parameter to compute the vote proportions. Set k = 7.
  • Use the attr() function to obtain the vote proportions for the predicted class. These are stored in the attribute "prob".
  • Examine the first several vote outcomes and percentages using the head() function to see how the confidence varies from sign to sign.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Use the prob parameter to get the proportion of votes for the winning class
sign_pred <- ___

# Get the "prob" attribute from the predicted classes
sign_prob <- attr(___, "___")

# Examine the first several predictions
head(___)

# Examine the proportion of votes for the winning class
head(___)
Edit dan Jalankan Kode