September 2019
Intermediate to advanced
420 pages
10h 29m
English
Returning to our kNN classifier, we find that we have only one hyperparameter to tune: k. Typically, you would have a much larger number of open parameters to mess with, but the kNN algorithm is simple enough for us to manually implement a grid search.
Before we get started, we need to split the dataset as we have done before into training and test sets:
In [1]: from sklearn.datasets import load_iris... import numpy as np... iris = load_iris()... X = iris.data.astype(np.float32)... y = iris.targetIn [2]: X_train, X_test, y_train, y_test = train_test_split(... X, y, random_state=37... )
Read now
Unlock full access