Exemplo n.º 1
0
 def test_transform_unseen(self, X, y, handle_unseen, expected):
     enc = TargetEncoder(cols=['cat'], handle_unseen=handle_unseen)
     X = pd.DataFrame(X, columns=['cat'])
     enc.fit(X, pd.Series(y))
     X.iloc[0, 0] = 'foo'
     result = enc.transform(X)
     assert_array_almost_equal(result, pd.DataFrame(expected), decimal=3)
Exemplo n.º 2
0
 def target_encoding(cls, X, Y=None, encoder=None):
     cols = ['some_id', 'other_id']
     if encoder is None:
         encoder = TargetEncoder(cols=cols, min_samples=5, smoothing=5)
         encoder.fit(X, Y)
     encoded = encoder.transform(X).rename(
         columns={c: 'tgt_enc_{}'.format(c)
                  for c in cols})
     return pd.concat([X[cols], encoded], axis=1), encoder