title: sklearn How to use MultiOutputClassifier with multi-label text classification
body: <p>I am trying to do multi-output multi-label multi-class text classification. The below example works, but I know it's not properly using the MultiOutputClassifier. I believe the point to it is to only have to train once and fit once, even for multiple outputs. How can I do this with a single pass through my data?</p>
  
  <pre><code>import numpy as np
  from sklearn.pipeline import Pipeline
  from sklearn.feature_extraction.text import CountVectorizer
  from sklearn.svm import LinearSVC
  from sklearn.feature_extraction.text import TfidfTransformer
  from sklearn.multiclass import OneVsRestClassifier
  from sklearn.preprocessing import MultiLabelBinarizer
  from sklearn.multioutput import MultiOutputClassifier
  
  X_train = np.array(["new york is a really big city",
                      "new york was originally dutch",
                      "the big apple is huge",
                      "new york is also called the big apple",
                      "nyc is nice",
                      "people abbreviate new york city as nyc",
                      "edinburgh is a small city in great britain",
                      "a northern city in great britain is edinburgh",
                      "edinburgh is in the uk",
                      "edinburgh is in england",
                      "edinburgh is in great britain",
                      "edinburgh is not big",
                      "edinburgh hosts the holyrood palace and new york hosts the empire state building",
                      "nyc is big and edinburgh is smaller",
                      "i like edinburgh better than new york"])
  y_train_text_1 = [["new york"],["new york"],["new york"],["new york"],["new york"],
                  ["new york"],["edinburgh"],["edinburgh"],["edinburgh"],["edinburgh"],
                  ["edinburgh"],["edinburgh"],["new york","edinburgh"],["edinburgh"],["new york","edinburgh"]]
  y_train_text_2 = [["big"],[""],["big"],["big"],[""],
                  [""],["small"],[""],[""],[""],
                  [""],["big"],[""],["big","small"],[""]]
  
  X_test = np.array(['nice day in nyc',
                     'my big day in edinburgh',
                     'edinburgh is small but nyc is big',
                     'it is raining in britain',
                     'it is raining in britain and the big apple',
                     'it is raining in britain and nyc',
                     'hello welcome to new york. enjoy it here and edinburgh too'])
  
  mlb_1 = MultiLabelBinarizer()
  Y_1 = mlb_1.fit_transform(y_train_text_1)
  
  classifier = Pipeline([
      ('vectorizer', CountVectorizer()),
      ('tfidf', TfidfTransformer()),
      ('clf', MultiOutputClassifier(OneVsRestClassifier(LinearSVC())))])
  
  classifier.fit(X_train, Y_1)
  predicted = classifier.predict(X_test)
  all_labels = mlb_1.inverse_transform(predicted)
  
  print('city name classifier:')
  for item, labels in zip(X_test, all_labels):
      print('{0} =&gt; {1}'.format(item, ', '.join(labels)))
  
  # Now fit on second output - can I do it all at once?
  mlb_2 = MultiLabelBinarizer()
  Y_2 = mlb_2.fit_transform(y_train_text_2)
  classifier.fit(X_train, Y_2)
  predicted = classifier.predict(X_test)
  all_labels = mlb_2.inverse_transform(predicted)
  
  print('city size classifier:')
  for item, labels in zip(X_test, all_labels):
      print('{0} =&gt; {1}'.format(item, ', '.join(labels)))
  </code></pre>
  
  <p>The output from running it:</p>
  
  <pre><code>city name classifier:
  nice day in nyc =&gt; new york
  my big day in edinburgh =&gt; edinburgh
  edinburgh is small but nyc is big =&gt; edinburgh
  it is raining in britain =&gt; edinburgh
  it is raining in britain and the big apple =&gt; edinburgh
  it is raining in britain and nyc =&gt; edinburgh
  hello welcome to new york. enjoy it here and edinburgh too =&gt; edinburgh, new york
  city size classifier:
  nice day in nyc =&gt; 
  my big day in edinburgh =&gt; 
  edinburgh is small but nyc is big =&gt; big, small
  it is raining in britain =&gt; 
  it is raining in britain and the big apple =&gt; big
  it is raining in britain and nyc =&gt; 
  hello welcome to new york. enjoy it here and edinburgh too =&gt; 
  </code></pre>