title: One hot encoding of string categorical features
body: <p>I'm trying to perform a one hot encoding of a trivial dataset. </p>
  
  <pre><code>data = [['a', 'dog', 'red']
          ['b', 'cat', 'green']]
  </code></pre>
  
  <p>What's the best way to preprocess this data using Scikit-Learn?</p>
  
  <p>On first instinct, you'd look towards Scikit-Learn's <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html#sklearn.preprocessing.OneHotEncoder" rel="noreferrer">OneHotEncoder</a>. But the one hot encoder doesn't support strings as features; it only discretizes integers.</p>
  
  <p>So then you would use a <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html" rel="noreferrer">LabelEncoder</a>, which would encode the strings into integers. But then you have to apply the label encoder into each of the columns and store each one of these label encoders (as well as the columns they were applied on). And this feels extremely clunky.</p>
  
  <p>So, what's the <strong>best</strong> way to do it in Scikit-Learn?</p>
  
  <p>Please don't suggest <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.get_dummies.html" rel="noreferrer">pandas.get_dummies</a>. That's what I generally use nowadays for one hot encodings. However, its limited in the fact that you can't encode your training / test set separately.</p>