<p>This method is simply <em>Impact Coding</em> the categorial variables.</p>

<p>If your categorical column has the categories {C1,C2,C3,...}, then impact coding is done as follows:</p>

<pre><code>                         Impact(category = Ci) = E[y|Ci] - E[y]
</code></pre>

<p>During training, for each category, (Ci), it calculates the difference between the mean output (given that category, i.e. a posteriori) and the overall expected value of the dependent variable (a priori). For more reference on impact coding, you can refer to this paper <a href="https://arxiv.org/abs/1611.09477v3" rel="nofollow noreferrer">https://arxiv.org/abs/1611.09477v3</a> (Page10)</p>

<p>In the testing phase, to convert the categorial variables of the testing data to their impact codes, it uses the same expected value of 'y' as it used for the training data. Since this is an expected value, it doesn't matter if the training data has more number of samples than the testing data (as long as the distribution of 'y' is similar in both the datasets).</p>
How does backward difference encoding work for testing set?
<p>According to this website (<a href="http://www.statsmodels.org/dev/contrasts.html" rel="nofollow noreferrer">http://www.statsmodels.org/dev/contrasts.html</a><a href="http://www.statsmodels.org/dev/contrasts.html" rel="nofollow noreferrer">enter link description here</a>), the definition of backward difference encoding is '<strong>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.</strong>' </p>

<p>What I don't understand is if this encoding method relies on the dependent variable (same thing as output variable if I understand correctly), how can we perform backward difference encoding with the testing set when dependent variable is not given to the model ahead of time? In the training set, values for the dependent variable is given but in testing set they are not given. Can anybody advise?</p>