title: How to pickle a sklearn pipeline for multi label classifier/one vs rest classifier?
body: <p>I am trying to create a multi-label classifier using the one vs rest classifier wrapper. </p>
  
  <p>I used a pipeline for TFIDF and the classifier. </p>
  
  <p>When fitting the pipeline, I have to loop through my data by category and then fit the pipeline each time to make predictions for each category. </p>
  
  <p>Now, I want to export this like how one would usually export a fitted model using pickle or joblib. </p>
  
  <p>Example:</p>
  
  <pre><code>pickle.dump(clf,'clf.pickle')
  </code></pre>
  
  <p>How can I do this with the pipeline? Even if I pickle the pipeline, do I still need to fit the pipeline every time when I want to predict on a new keyword?</p>
  
  <p>Example: </p>
  
  <pre><code>pickle.dump(pipeline,'pipeline.pickle')
  pipeline = pickle.load('pipeline.pickle')
  
  for category in categories:
      pipeline.fit(X_train, y_train[category])
      pipeline.predict(['kiwi'])
      print (predict)
  </code></pre>
  
  <p>If I skip the <code>pipeline.fit(X_train, y_train[category])</code> after loading the pipeline, I only get a single value array in predict. If I fit the pipeline, I get a three value array.</p>
  
  <p>Also, how can I incorporate the grid search into my pipeline for export?</p>
  
  <p><strong>raw_data</strong></p>
  
  <pre><code>keyword        class1 class2 class3
  "orange apple"    1      0      1
  "lime lemon"      1      0      0
  "banana"          0      1      0
  
  categories = ['class1','class2','class3']
  </code></pre>
  
  <p><strong>pipeline</strong></p>
  
  <pre><code>SVC_pipeline = Pipeline([
                  ('tfidf', TfidfVectorizer(stop_words=stop_words)),
                  ('clf', OneVsRestClassifier(LinearSVC(), n_jobs=1)),
              ])
  </code></pre>
  
  <p><strong>Gridsearch (dont know how to incorporate this into the pipeline</strong>)</p>
  
  <pre><code>parameters = {'tfidf__ngram_range': [(1, 1), (1, 2)],
                'tfidf__use_idf': (True, False),
                'tfidf__max_df': [0.25, 0.5, 0.75, 1.0],
                'tfidf__max_features': [10, 50, 100, 250, 500, 1000, None],
                'tfidf__stop_words': ('english', None),
                'tfidf__smooth_idf': (True, False),
                'tfidf__norm': ('l1', 'l2', None),
                }
  
  grid = GridSearchCV(SVC_pipeline, parameters, cv=2, verbose=1)
  grid.fit(X_train, y_train)
  </code></pre>
  
  <p><strong>Fitting pipeline</strong></p>
  
  <pre><code>for category in categories:
      print('... Processing {}'.format(category))
  
      SVC_pipeline.fit(X_train, y_train[category])
  
      # compute the testing accuracy
      prediction = SVC_pipeline.predict(X_test)
      print('Test accuracy is {}'.format(accuracy_score(y_test[category], prediction)))
  </code></pre>