to use search over spaces that are not grids in some casestrying all possible combinations of all parameters as gridsearchcv usually doesis not good idea for examplesvc has kernel parameterand depending on which kernel is chosenother parameters will be relevant if ker nel='linear'the model is linearand only the parameter is used if kernel='rbf'both the and gamma parameters are used (but not other parameters like degreein this casesearching over all possible combinations of cgammaand kernel wouldn' make senseif kernel='linear'gamma is not usedand trying different values for gamma would be waste of time to deal with these kinds of "conditionalparametersgridsearchcv allows the param_grid to be list of dictionaries each dictionary in the list is expanded into an independent grid possible grid search involving kernel and parameters could look like thisin[ ]param_grid [{'kernel'['rbf']' '[ ]'gamma'[ ]}{'kernel'['linear']' '[ ]}print("list of grids:\ {}format(param_grid)out[ ]list of grids[{'kernel'['rbf']' '[ ]'gamma'[ ]}{'kernel'['linear']' '[ ]}in the first gridthe kernel parameter is always set to 'rbf(not that the entry for kernel is list of length one)and both the and gamma parameters are varied in the second gridthe kernel parameter is always set to linearand only is varied now let' apply this more complex parameter searchin[ ]grid_search gridsearchcv(svc()param_gridcv= grid_search fit(x_trainy_trainprint("best parameters{}format(grid_search best_params_)print("best cross-validation score{ }format(grid_search best_score_)out[ ]best parameters{' ' 'kernel''rbf''gamma' best cross-validation score grid search