title: scikit-learn: How to compose LabelEncoder and OneHotEncoder with a pipeline?
body: <p>While preprocessing the labels for a machine learning classifying task, I need to one hot encode the labels which take string values. It happens that <code>OneHotEncoder</code> from <code>sklearn.preprocessing</code> or <code>to_categorical</code> from <code>kera.np_utils</code> require <code>int</code> inputs. This means that I need to precede the one hot encoder with a <code>LabelEncoder</code>. I have done it by hand with a custom class:</p>
  
  <pre><code>class LabelOneHotEncoder():
      def __init__(self):
          self.ohe = OneHotEncoder()
          self.le = LabelEncoder()
      def fit_transform(self, x):
          features = self.le.fit_transform( x)
          return self.ohe.fit_transform( features.reshape(-1,1))
      def transform( self, x):
          return self.ohe.transform( self.la.transform( x.reshape(-1,1)))
      def inverse_tranform( self, x):
          return self.le.inverse_transform( self.ohe.inverse_tranform( x))
      def inverse_labels( self, x):
          return self.le.inverse_transform( x)
  </code></pre>
  
  <p>I am confident there must a way of doing it within the sklearn API using a <code>sklearn.pipeline</code>, but when using:</p>
  
  <pre><code>LabelOneHotEncoder = Pipeline( [ ("le",LabelEncoder), ("ohe", OneHotEncoder)])
  </code></pre>
  
  <p>I get the error <code>ValueError: bad input shape ()</code> from the <code>OneHotEncoder</code>. My guess is that the output of the <code>LabelEncoder</code> needs to be reshaped, by adding a trivial second axis. I am not sure how to add this feature though.</p>