title: Python: getting AttributeError: 'LogisticRegression' object has no attribute 'classes_' when tryig to use predict
body: <p>I'm trying to predict demographic attributes from Twitter using LogisticRegression but I'm getting "File "Anaconda\lib\site-packages\sklearn\linear_model\base.py", line 341, in predict
      return self.classes_[indices]
  AttributeError: 'LogisticRegression' object has no attribute 'classes_'"</p>
  
  <p>The Code:</p>
  
  <pre><code>_predictor = Predictor()
  pred = _predictor.predict_attribute(_model_dir, attr, tweetsArr, _sent_vocab_file, _emo_vocab_file)
  
  
  
  class Predictor:
      def __init__(self):
          self.clf = linear_model.LogisticRegression(C=1.0, dual=False, penalty='l2', tol=1e-6)
          self.hv = HashingVectorizer(ngram_range=(1, 2), binary=True)
          self.pred_classes = []
          self.pred_probs = []
  
  
  
  def predict_attribute(self, dir, attr, tweets, sent_vocab_file, emo_vocab_file):
      pred_dict = {}
      # loading pre-trained model
      current = os.getcwd()
      if dir not in os.getcwd():
          os.chdir(dir)
          for file in glob.glob("*.pkl"):
              if attr in file:
                  self.clf = joblib.load(file)
      pred_probs = self.clf.predict_proba(features).tolist()
      pred_classes = self.clf.predict(features).tolist()
      pred_dict['pred_probs'] = pred_probs
      pred_dict['pred_class'] = pred_classes
      return pred_dict
  </code></pre>
  
  <p>the full traceback:</p>
  
  <pre><code>C:\Users\orensig\Anaconda\lib\site-packages\sklearn\base.py:315: UserWarning: Trying to unpickle estimator LabelEncoder from version pre-0.18 when using version 0.18.1. This might lead to breaking code or invalid results. Use at your own risk.
  
  UserWarning)
  C:\Users\orensig\Anaconda\lib\site-packages\sklearn\base.py:315: UserWarning: Trying to unpickle estimator LogisticRegression from version pre-0.18 when using version 0.18.1. This might lead to breaking code or invalid results. Use at your own risk.
  
  UserWarning)
  Traceback (most recent call last):
    File "Algo/streaming_tweets/Eugenia_predict_psycho-demographics_emotions.py", line 71, in predict_attribute
  
  pred_classes = self.clf.predict(features).tolist()
    File "C:\Users\orensig\Anaconda\lib\site-packages\sklearn\linear_model\base.py", line 341, in predict
  
  return self.classes_[indices]
  AttributeError: 'LogisticRegression' object has no attribute 'classes_'
  
  Traceback (most recent call last):
    File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.1.2\helpers\pydev\pydevd.py", line 1585, in &lt;module&gt;
  
  globals = debugger.run(setup['file'], None, None, is_module)
    File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.1.2\helpers\pydev\pydevd.py", line 1015, in run
  
  pydev_imports.execfile(file, globals, locals)  # execute the script
    File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.1.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
      exec(compile(contents+"\n", file, 'exec'), glob, loc)
  
  File "Algo/streaming_tweets/Eugenia_predict_psycho-demographics_emotions.py", line 251, in &lt;module&gt;
  
  prediction = pred.predict_attribute(model_dir, attr, tweets1, sent_vocab_file, emo_vocab_file)
  
  File "Algo/streaming_tweets/Eugenia_predict_psycho-demographics_emotions.py", line 77, in predict_attribute
  
  pred_dict['pred_class'] = pred_classes
  UnboundLocalError: local variable 'pred_classes' referenced before assignment
  
  Process finished with exit code 1
  </code></pre>