3

I noticed H2O has released the target mean encoding

http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-munging/target-encoding.html

It only comes with an R code example. Does anyone have a Python example?

Darren Cook
  • 27,837
  • 13
  • 117
  • 217
Gavin
  • 1,411
  • 5
  • 18
  • 31
  • 1
    For your future convenience please note that documentation that you have provided link to comes with both R and Python code examples. Please look for a toggle above code snippets. Toggles work page-wise so it is possible to change language with just one click on any of them. – Deil May 13 '19 at 11:04

1 Answers1

3

Like this:

from h2o.targetencoder import TargetEncoder

# Fit target encoding on training data
targetEncoder = TargetEncoder(x= ["addr_state", "purpose"], y = "bad_loan", fold_column = "cv_fold_te")
targetEncoder.fit(ext_train)

But this requires version at least 3.22

Here is a link to an example: https://github.com/h2oai/h2o-tutorials/blob/78c3766741e8cbbbd8db04d54b1e34f678b85310/best-practices/feature-engineering/feature_engineering.ipynb

And the link to code itself: https://github.com/h2oai/h2o-3/blob/master/h2o-py/h2o/targetencoder.py

Andrey Lukyanenko
  • 3,679
  • 2
  • 18
  • 21
  • 1
    can you share me the link about where you find the example? I didn't find in H2O document – Gavin Jan 09 '19 at 03:25
  • Sure. It is "hidden", but I have found it some time ago: https://github.com/h2oai/h2o-tutorials/blob/78c3766741e8cbbbd8db04d54b1e34f678b85310/best-practices/feature-engineering/feature_engineering.ipynb And the link to code itself: https://github.com/h2oai/h2o-3/blob/master/h2o-py/h2o/targetencoder.py – Andrey Lukyanenko Jan 09 '19 at 05:25
  • have you tested the Python code for target encoder? I some some error using the sample code https://stackoverflow.com/questions/55306686/h2o-target-mean-encoder-frames-are-being-sent-in-the-same-order-error – Gavin Mar 22 '19 at 19:54
  • 1
    @Gavin issue is fixed and should be available in the next fix release 3.24.0.3 – Deil May 13 '19 at 10:57