05-More hyperparameters in grid search and k nearest neighbor algorithm

  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

Insert picture description here

2. Define the parameters required by Grid Search

Insert picture description here

3. Specific use

Insert picture description here
Insert picture description here

4. More parameters can be passed in in GridSearch

Insert picture description here


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.
Insert picture description here
Interested students can check the official manual


For specific codes, please refer to 06 grid search and k nearest neighbor algorithm for more hyperparameters

Guess you like

Origin blog.csdn.net/qq_41033011/article/details/108972023