Mai Mai - 1 year ago 83
Python Question

Using cross validation on all combinations in grid search

I'm using support vector machines to classify some data. I've split my data into a training set and a validation set, and I've used GridSearchCV to train with different hyperparameters and find the best. Now, I would like to print the result for all those, both on the training set and the validation set. The training set is easy enough, given that GridSearchCV has an attribute called grid_scores_(I'm using scikit-learn version 1.17.1), which I can print to get all the results on my training set. However, I would like to be able to print the same thing, but for my validation set. I can get the result for the best one by writing

print(clf.score(X_test, y_test))

I would like if I can get this, but for all the combinations, not just the best. Is this posible?

Answer Source

Yes you can. There is a parameter called verbose that you can set in your GridSearchCV. It controls the verbosity of the messages shown in the console.

verbose is an integer : the higher, the more messages. For exemple if you set verbose = 3 you will get the parameters of your cross validation and the score for each combination.

You can try different values for this parameter.

Hope this helped !

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download