Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in AI and Deep Learning by (50.2k points)

The GridSearchCV uses 'scoring' to select the best estimator. After train the GridSearchCV, I would like to see the score for each combination. Does GridSearchCV store all scores for each parameter combination? If it does how to get the scores? Thanks.

Here is an example code that I used in another post.

from sklearn.feature_extraction.text import CountVectorizer

from sklearn.feature_extraction.text import TfidfTransformer

from sklearn.grid_search import GridSearchCV

from sklearn.pipeline import Pipeline

from sklearn.naive_bayes import MultinomialNB

X_train = ['qwe rtyuiop', 'asd fghj kl', 'zx cv bnm', 'qw erty ui op', 'as df ghj kl', 'zxc vb nm', 'qwe rt yu iop', 'asdfg hj kl', 'zx cvb nm',

          'qwe rt yui op', 'asd fghj kl', 'zx cvb nm', 'qwer tyui op', 'asd fg hjk l', 'zx cv b nm', 'qw ert yu iop', 'as df gh jkl', 'zx cvb nm',

           'qwe rty uiop', 'asd fghj kl', 'zx cvbnm', 'qw erty ui op', 'as df ghj kl', 'zxc vb nm', 'qwe rtyu iop', 'as dfg hj kl', 'zx cvb nm',

          'qwe rt yui op', 'asd fg hj kl', 'zx cvb nm', 'qwer tyuiop', 'asd fghjk l', 'zx cv b nm', 'qw ert yu iop', 'as df gh jkl', 'zx cvb nm']    

y_train = ['1', '2', '3', '1', '1', '3', '1', '2', '3',

          '1', '2', '3', '1', '4', '1', '2', '2', '4', 

          '1', '2', '3', '1', '1', '3', '1', '2', '3',

          '1', '2', '3', '1', '4', '1', '2', '2', '4']    

parameters = { 'clf__alpha': (1e-1, 1e-2),

             'vect__ngram_range': [(1,2),(1,3)],

             'vect__max_df': (0.9, 0.98)


text_clf_Pipline_MultinomialNB = Pipeline([('vect', CountVectorizer()),('tfidf', TfidfTransformer()),('clf', MultinomialNB()),])

gs_clf = GridSearchCV(text_clf_Pipline_MultinomialNB, parameters, n_jobs=-1)  

gs_classifier =, y_train)

1 Answer

0 votes
by (108k points)

Yes, GridSearchCV does store all scores for each parameter combinations with the help of score(self, X, y=None)

Which returns the score on the given data, if the estimator has been refit.

This uses the score defined by scoring where provided and the best_estimator_.score method otherwise.


For more knowledge, you can refer the following link:

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.2k users

Browse Categories