0

I am learning the H2O TargetEncoder function from h2o.targetencoder. I am wondering, is there a way that we can export the mapping table for each level of the categorical variable?

For example, if we have 2 categorical variable for 50 US states and 5 weekdays. Can TargetEncoder export a results table with the mapped numeric value for the 50 states and 5 weekdays?

Gavin
  • 1,411
  • 5
  • 18
  • 31
  • In this [tutorial](http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-munging/target-encoding.html#perform-target-encoding), a variable named `te_map` is returned by the function `h2o.target_encode_create()`. Have you tried looking at the `te_map` variable and does it have the information you're looking for? – Joe Mar 25 '19 at 23:45
  • that is R code, is there a Python example? – Gavin Mar 26 '19 at 04:48
  • The examples [here](https://stackoverflow.com/questions/54102766/is-h2o-target-mean-encoding-available-in-python) don't explicitly say it, however we can see in the [source code](https://github.com/h2oai/h2o-3/blob/master/h2o-py/h2o/targetencoder.py) that `targetEncoder.fit(ext_train)` returns a mapping. – Joe Mar 26 '19 at 06:39
  • yes, I saw there it can return _encodingMap. It is a h2o.expr.H2OCache object. I am still not sure how to get the mapping table. – Gavin Mar 26 '19 at 18:17

1 Answers1

0

Building on the example here, you can access the mapping after calling targetEncoder.fit(ext_train) with:

encodingMapFramesKeys = list(map(lambda x: h2o.get_frame(x['key']['name']), targetEncoder._encodingMap.frames))

encodingMapFramesKeys[0].describe()
encodingMapFramesKeys[1].describe()
Joe
  • 268
  • 2
  • 5