Skip to content
ml-recall

#k-nearest-neighbors

1 question from Nearest Neighbors & Kernel Methods

Timed test

1 question · 1 min · score and explanations at the end

Take a test
Q 1 / 1Score 0 / 0

Question 1: Short answer

mediumAI-checkedNearest Neighbors & Kernel Methods
from sklearn.neighbors import KNeighborsClassifier

X = [[0.0], [1.0], [4.0]]
y = [0, 0, 1]
for w in ["uniform", "distance"]:
    knn = KNeighborsClassifier(n_neighbors=3, weights=w).fit(X, y)
    print(w, knn.predict([[3.5]])[0])

The loop prints the class predicted for x=3.5x = 3.5: with "uniform" it prints , and with "distance" it prints .

Fill in every blank (hints in the boxes). Enter moves to the next blank.