Comparing randomized search and grid search for hyperparameter estimation
Compare several strategies to optimize the hyperparameters of a linear SVM
trained with stochastic gradient descent. We score the candidates with the
one-vs-rest ROC AUC (roc_auc_ovr), which evaluates the ranking quality of the
predicted class probabilities rather than the raw accuracy of the hard labels.
We start with an exhaustive grid search
(GridSearchCV) that evaluates every combination
of a discretized parameter grid. Because the grid is fixed, we are forced to fit
every configuration and we may even miss a good combination that falls between
two grid points.
We then run a randomized search
(RandomizedSearchCV) that samples the parameter
space instead of discretizing it. With a smaller budget it explores the space
more efficiently and reaches an equivalent solution with fewer iterations.
Finally, we run a successive halving search () that samples even more candidates but keeps the cost low by evaluating them on a small number of training samples first and discarding the unpromising ones early. It combines a large number of candidates with a reduced fit and predict time in the early iterations.