title: how to maintain natural order when label encoding with scikit learn
body: <p>I'm trying to fit a model for a decision tree classifier with scikit-learn module. I have 5 features and one of those is categorical, not numerical</p>
  
  <pre><code>from sklearn.tree import DecisionTreeClassifier
  from sklearn.preprocessing import LabelEncoder
  
  df = pd.read_csv()
  labelEncoders = {}
  for column in df.dtypes[df.dtypes == 'object'].index:
      labelEncoders[column] = LabelEncoder()
      df[column] = labelEncoders[column].fit_transform(df[column])
      print(labelEncoders[column].inverse_transform([0, 1, 2])) #['High', 'Low', 'Normal']
  </code></pre>
  
  <p>I'm new to ML and I've been reading about the need to encode categorical features before feeding the data frame to the model, and how there are encoding variants like <em>label encoding</em> and <em>one hot encoding</em>.</p>
  
  <p>Now, according to most literature, label encoding should or could be used when the values of the feature can be naturally ordered, for instance, <strong>'Low', 'Normal', 'High'</strong>; otherwise one should use one hot encoding so the model doesn't establish a misleading order relationship between the values when there is none that would make sense semantically, for example, <strong>'Brazil', 'Congo', 'Czech Republic'</strong>.</p>
  
  <p>So, that's where I'm at with the logic behind choosing a coding strategy, and that's why I'm asking this: </p>
  
  <p>how can I make scikit-learn's <code>LabelEncoder</code> keep the natural order of the values, how can I make it encode like this:</p>
  
  <pre><code>Low -&gt; 0
  Normal -&gt; 1
  High -&gt; 2
  </code></pre>
  
  <p>and NOT the way it's doing it now:</p>
  
  <pre><code>High -&gt; 0
  Low -&gt; 1
  Normal -&gt; 2
  </code></pre>
  
  <p>Can this be done at all? Is it actually the encoder's task? Do I have to do it somewhere else before the encoding?</p>
  
  <p>Thanks</p>