In the previous blog, I introduced how to use grid search to find the best hyperparameters in machine learning algorithms. However, our grid search process uses our own for loop. In this process, we found that for some hyperparameters, they are interdependent. For example, when we search for p corresponding to the Minkowski distance, it is meaningful only when weights="distance".
In order to make it more convenient for us to use grid search to find the best hyperparameters, sklearn encapsulates a special method for grid search Grid Search
.
Let's use it in detail below.
1. Get the data set we need
2. Define the parameters required by Grid Search
3. Specific use
4. More parameters can be passed in in GridSearch
More distance definition
In addition to the Minkowski distance mentioned earlier, we can also use other distances. For example, between two samples, we can use statistical similarity to define the distance between them, and similarity can be defined in many ways, as shown in the figure below.
Interested students can check the official manual
For specific codes, please refer to 06 grid search and k nearest neighbor algorithm for more hyperparameters