Search code examples
javarproduction-environmenth2o

Could I export model trained with h2o to Java code?


Could I export model trained with h2o to Java code when using h2o from level of R package ?


Solution

  • Yes. This is exactly what the POJO is for. In your R script, if m is your model, then you can get the POJO with:

    h2o.download_pojo(m, "/path/to/save/in/");
    

    This will choose the filename, and create a java file in the directory you give. By default it will also download the jar file you need.

    If saving to the local file system is not desirable, don't give a path (i.e. do just h2o.download_pojo(m)) and it will output the java class to your R session, where you could capture the output, and do something with that.

    Also take a look at h2o.download_mojo(), which gives a different format. It is for tree models, which can get very big (in fact it only supports random forest, GBM and GLM currently).

    More info on both POJO and MOJO here: http://docs.h2o.ai/h2o/latest-stable/h2o-docs/pojo-quick-start.html