title: backward difference encoding
body: <p><a href="https://www.datacamp.com/community/tutorials/categorical-data" rel="nofollow noreferrer">This tutorial</a> discussed the information about BackWard difference encoding:</p>
  <blockquote>
  <ol start="5">
  <li>Backward Difference Encoding</li>
  </ol>
  <p>This technique falls under the contrast coding system for categorical features. A feature of K categories, or levels, usually enters a regression as a sequence of K-1 dummy variables. In backward difference coding, the mean of the dependent variable for a level is compared with the mean of the dependent variable for the prior level. This type of coding may be useful for a nominal or an ordinal variable.</p>
  <p>If you want to learn other contrast coding methods you can check out this resource.</p>
  <p>The code structure is pretty much the same as any method in the category_encoders library, just this time you will call BackwardDifferenceEncoder from it</p>
  </blockquote>
  <p>as it said, it will transform k categories into k-1 binary categories.</p>
  <p>I used this method on its database. For 'carriers', we had 11 categories and what we received after encoding is also 11 categories. Isn't it supposed to be 10 categories or 10 columns of binary values?</p>
  <pre><code>df_flights = pd.read_csv('https://raw.githubusercontent.com/ismayc/pnwflights14/master/data/flights.csv')
  
  df_flights.head()
  
  df_flights['carrier'].unique()
  </code></pre>
  <p>so we have 11 unique categories.</p>
  <pre><code>!pip install category_encoders
  import category_encoders as ce
  cat_df_flights = df_flights.select_dtypes(include=['object']).copy()
  encoder = ce.BackwardDifferenceEncoder(cols=['carrier'])
  df_bd = encoder.fit_transform(cat_df_flights)
  
  df_bd.head()
  </code></pre>
  <p>the outcome is also 11 columns of binary data but based on what this tutorial said, it should be 10...</p>