'LinearSVC' object has no attribute 'classes_'
Question: I have several samples of images and I would like to predict if those images
contain text/characters.

I get an error when I try running my code at this step :

    
    
    model = cPickle.load(f)
    is_text = model.predict(image_samples)
    

image_samples are my samples and model looks like this :

    
    
    Pipeline(steps=[
        ('hog', HOGFeatures(cells_per_block=(2, 2), orientations=10,
                            pixels_per_cell=(5, 5), size=(20, 20))),
        ('clf', LinearSVC(C=2.0, class_weight=None, dual=True,
                          fit_intercept=True,
                          intercept_scaling=1, loss='l2', max_iter=None,
                          multi_class='ovr', penalty='l2',
                          random_state=None, tol=0.0001, verbose=0))
    ])
    

The error message I get is :

    
    
    File "/home/parallels/Desktop/Python/ImageTextRecognition-master/userimageski.py", line 104, in select_text_among_candidates
    is_text = model.predict(self.candidates['flattened'])
    
    File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/metaestimators.py", line 37, in <lambda>
    out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs)
    
    File "/usr/local/lib/python2.7/dist-packages/sklearn/pipeline.py", line 180, in predict
    return self.steps[-1][-1].predict(Xt)
    
    File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/base.py", line 228, in predict
    return self.classes_[indices]
    AttributeError: 'LinearSVC' object has no attribute 'classes_'
    

Could anyone help me ? Thank you very much


Answer: I had the same problem . It is actually an issue with sklearn versions. run
python2.7 in the terminal and check `>>> import sklearn` `>>>
sklearn.__version__` if you have a very previous version than current and as
of now 0.17.1 is current then you need to upgrade sklearn . Just do `sudo pip
install -U scikit-learn` to upgrade and re run the code

