Get corresponding classes to predict_proba (GridSearchCV sklearn)

I’m using GridSearchCV and a pipeline to classify som text documents. A code snippet is inserted below

clf = Pipeline([('vect', TfidfVectorizer()), ('clf', SVC())])
parameters = {'vect__ngram_range' : [(1,2)], 'vect__min_df' : [2], 'vect__stop_words' : ['english'],
                  'vect__lowercase' : [True], 'vect__norm' : ['l2'], 'vect__analyzer' : ['word'], 'vect__binary' : [True], 
                  'clf__kernel' : ['rbf'], 'clf__C' : [100], 'clf__gamma' : [0.01], 'clf__probability' : [True]} 
grid_search = GridSearchCV(clf, parameters, n_jobs = -2, refit = True, cv = 10)
grid_search.fit(corpus, labels)

My problem is that when using grid_serach.predict_proba(new_doc) and then want to find out what classes the probabilities corresponds to with grid_search.classes_, I get the following error

AttributeError: ‘GridSearchCV’ object has no attribute ‘classes_’

What have I missed? I thought that if the last “step” in the pipeline was a classifier, then the return of GridSearchCV is also a classifier. Hence one can use the attributes of that classifier, e.g. classes_

Thanks in advanced!


Source: python

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.