Question

I have set up a GridSearchCV and have a set of parameters, with I will find the best combination of parameters. My GridSearch consists of 12 candidate models total.

However, I am also interested in seeing the accuracy score of all of the 12, not just the best score, as I can clearly see by using the .best_score_ method. I am curious about opening up the black box that GridSearch sometimes feels like.

I see a scoring= argument to GridSearch, but I can't see any way to iteratively print out scores.

Any advice is appreciated. Thanks in advance.

Was it helpful?

Solution

Use the grid_scores_ attribute:

>>> clf = GridSearchCV(LogisticRegression(), {'C': [1, 2, 3]})
>>> clf.fit(np.random.randn(10, 4), np.random.randint(0, 2, 10))
GridSearchCV(cv=None,
       estimator=LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
          intercept_scaling=1, penalty='l2', random_state=None, tol=0.0001),
       fit_params={}, iid=True, loss_func=None, n_jobs=1,
       param_grid={'C': [1, 2, 3]}, pre_dispatch='2*n_jobs', refit=True,
       score_func=None, scoring=None, verbose=0)
>>> from pprint import pprint
>>> pprint(clf.grid_scores_)
[mean: 0.40000, std: 0.11785, params: {'C': 1},
 mean: 0.40000, std: 0.11785, params: {'C': 2},
 mean: 0.40000, std: 0.11785, params: {'C': 3}]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top