This is my code, it follows the answer solution but I’m running an error on the predictions line.
Preparing data and create training and test inputs and labels
X_train, X_test, y_train, y_test = model_selection.train_test_split(data, labels, test_size=0.2, random_state=1)
Initializing our model
knn_model = KNeighborsClassifier(n_neighbors=3)
Training our model with its training input data and labels
knn_model.fit(X_train, y_train)
Predict what the classes are based on the testing data
predictions = knn_model.predict(X_test)
Print the score on the testing data
print(“KNN Testing Set Accuracy:”)
print(accuracy_score(y_test, predictions)*100)
I tried to replace predictions with y_pred and I tried to split up the code into different cells. Solutions online with similar type errors say missing brackets but I have them
J. Doe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.