title: Pickled model with vectorizer
body: <p>I am pickling a model for later use. Then loading the model and running <code>predict_proba</code> on it. I get <code>ValueError: X has 1 features per sample; expecting 319</code>. Not sure if I am transforming it correctly</p>
  
  <pre><code>import csv, pickle
  from sklearn import svm
  
  from sklearn.feature_extraction.text import TfidfVectorizer
  from sklearn.calibration import CalibratedClassifierCV
  import numpy as np
  import operator
  
  train_data = []
  train_labels = []
  test_lables = []
  test_lables.append("nah")
  
  with open('training_file', 'r') as f:
      reader = csv.reader(f, dialect='excel', delimiter='\t')
      for row in reader:
          train_data.append(row[0])
          train_labels.append(row[1])
  
  lables = []
  
  for item in train_labels:
      if item in lables:
          continue
      else:
          lables.append(item)
  
  
  def linear_svc(train_data, train_labels):
  
      vectorizer = TfidfVectorizer()
      train_vectors = vectorizer.fit_transform(train_data)
      classifier_linear = svm.LinearSVC()
      clf = CalibratedClassifierCV(classifier_linear)   
      clf.fit(train_vectors, train_labels)
  
      with open('test', 'wb') as fi:
          pickle.dump(clf, fi)
  
  
  def run_classifier():    
      vectorizer = TfidfVectorizer()
      test_vectors = vectorizer.fit_transform(test_lables)
      with open('test', 'rb') as fi:
          clf = pickle.load(fi)
      prediction_linear = clf.predict_proba(test_vectors) 
      return prediction_linear
  
  
  #linear_svc(train_data, train_labels)
  sorted_intent_probability = run_classifier()
  print(sorted_intent_probability)
  </code></pre>
  
  <p>I first call the <code>linear_svc()</code> method. The model gets pickled. Then I call <code>run_classifier()</code>. What am I doing wrong here? Also, when I combine both the methods, it works fine:</p>
  
  <pre><code>def linear_svc(train_data, train_labels, test_lables):
  
      vectorizer = TfidfVectorizer()
      train_vectors = vectorizer.fit_transform(train_data)
      test_vectors = vectorizer.transform(test_lables)
      classifier_linear = svm.LinearSVC()
      clf = CalibratedClassifierCV(classifier_linear) 
  
      clf.fit(train_vectors, train_labels)
      prediction_linear = clf.predict_proba(test_vectors)
      return prediction_linear
  </code></pre>
  
  <p>Do I need to pickle the vectorizer as well and reuse it later?</p>