KNN on non-scaled data
Before adding standardization to your scikit-learn workflow, you'll first take a look at the accuracy of a K-nearest neighbors model on the wine
dataset without standardizing the data.
The knn
model as well as the X
and y
data and labels sets have been created already.
This exercise is part of the course
Preprocessing for Machine Learning in Python
Exercise instructions
- Split the dataset into training and test sets.
- Fit the
knn
model to the training data. - Print out the test set accuracy of your trained
knn
model.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Split the dataset and labels into training and test sets
X_train, X_test, y_train, y_test = ____(____, ____, stratify=y, random_state=42)
# Fit the k-nearest neighbors model to the training data
____
# Score the model on the test data
print(____.____(____, ____))