MulaiMulai sekarang secara gratis

k-Nearest Neighbors: Predict

Now you have fit a KNN classifier, you can use it to predict the label of new data points. All available data was used for training, however, fortunately, there are new observations available. These have been preloaded for you as X_new.

The model knn, which you created and fit the data in the last exercise, has been preloaded for you. You will use your classifier to predict the labels of a set of new data points:

X_new = np.array([[30.0, 17.5],
                  [107.0, 24.1],
                  [213.0, 10.9]])

Latihan ini adalah bagian dari kursus

Supervised Learning with scikit-learn

Lihat Kursus

Petunjuk latihan

  • Create y_pred by predicting the target values of the unseen features X_new using the knn model.
  • Print the predicted labels for the set of predictions.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Predict the labels for the X_new
y_pred = ____

# Print the predictions
print("Predictions: {}".format(____)) 
Edit dan Jalankan Kode