BaşlayınÜcretsiz başlayın

K-nearest neighbors for mushrooms

The Gaussian Naive Bayes classifier did a really good job for being an initial model. Let's now build a new model to compare it against the Naive Bayes.

In this case, the algorithm to use is a 5-nearest neighbors classifier. As the dummy features create a high-dimensional dataset, use the Ball Tree algorithm to make the model faster. Let's see how this model performs!

Bu egzersiz, kursun bir parçasıdır

Ensemble Methods in Python

Kursa Göz Atın

Egzersiz talimatları

  • Build a KNeighborsClassifier with 5 neighbors and algorithm = 'ball_tree' (to expedite the processing).
  • Fit the model to the training data.
  • Evaluate the performance on the test set using the accuracy score.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

# Instantiate a 5-nearest neighbors classifier with 'ball_tree' algorithm
clf_knn = ____(____, ____)

# Fit the model to the training set
____

# Calculate the predictions on the test set
pred = ____

# Evaluate the performance using the accuracy score
print("Accuracy: {:0.4f}".format(accuracy_score(y_test, pred)))
Kodu Düzenle ve Çalıştır