Hyperparameter search

This example showcases a simple grid search in one dimension, where we try different parameters for a model and pick the one with the best results on a holdout set.

Defining the image 

First, let’s build a custom image and install scikit-learn in it.

The Modal function 

Next, define the function. Note that we use the custom image with scikit-learn in it. We also take the hyperparameter k, which is how many nearest neighbors we use.

To do a hyperparameter search, let’s map over this function with different values for k, and then select for the best score on the holdout set: