0
0
ML Pythonprogramming~10 mins

K-Nearest Neighbors (KNN) in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the KNeighborsClassifier from scikit-learn.

ML Python
from sklearn.neighbors import [1]
Drag options to blanks, or click blank then click option'
AKNeighborsClassifier
BRandomForestClassifier
CLinearRegression
DSVC
Attempts:
3 left
2fill in blank
medium

Complete the code to create a KNN model with 3 neighbors.

ML Python
model = KNeighborsClassifier(n_neighbors=[1])
Drag options to blanks, or click blank then click option'
A10
B5
C1
D3
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to fit the KNN model on training data X_train and y_train.

ML Python
model.[1](X_train, y_train)
Drag options to blanks, or click blank then click option'
Atransform
Bscore
Cfit
Dpredict
Attempts:
3 left
4fill in blank
hard

Fill both blanks to predict labels for X_test and calculate accuracy score.

ML Python
predictions = model.[1](X_test)
accuracy = accuracy_score(y_test, [2])
Drag options to blanks, or click blank then click option'
Apredict
Bpredictions
Cfit
Dtransform
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a dictionary of predictions for each test sample with their index, predicted label, and distance to neighbors.

ML Python
results = {i: {'label': [1][i], 'distances': [2][i]} for i in range(len([3]))}
Drag options to blanks, or click blank then click option'
Apredictions
Bdistances
CX_test
Dy_test
Attempts:
3 left