Grid Searching in Machine Learning: Quick Explanation and Python Implementation

Evan Lutins
2 min readSep 6, 2017

Grid-searching is the process of scanning the data to configure optimal parameters for a given model. Depending on the type of model utilized, certain parameters are necessary. Grid-searching does NOT only apply to one model type. Grid-searching can be applied across machine learning to calculate the best parameters to use for any given model. It is important to note that Grid-searching can be extremely computationally expensive and may take your machine quite a long time to run. Grid-Search will build a model on each parameter combination possible. It iterates through every parameter combination and stores a model for each combination. Without further ado, lets jump into some examples and implementation.

For the sake of this article I will utilize Decision Trees to explain and implement Grid-Searching in Python.

Importing the necessary libraries

Instantiating the model

Establishing which parameters to Grid Search

Running the Grid Search. This step may take a long time to run depending on the data and number of parameters.

Fitting the Grid Search

Methods to Run on Grid-Search

--

--

Evan Lutins

University of Maryland graduate Current Data Scientist at Pinpoint