Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
2fill in blank
mediumComplete 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'
Attempts:
3 left
3fill in blank
hardFix 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'
Attempts:
3 left
4fill in blank
hardFill 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'
Attempts:
3 left
5fill in blank
hardFill 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'
Attempts:
3 left