Acumos H2O Model Runner Python Developer Guide

This predictor will run predictions for H2O POJO (Non compiled Java code) as well as MOJO (Compiled jars) models. This service has a dependency to model-management to download the models. AsyncPredictions and status methods are yet to be implemented in this version. All the model runners follow a similar design pattern in that the expose the 3 endpoints asyncpredictions, syncpredictions and status.

Running this predictor in Windows requires changing the classpath argument as follows however it is assumed to be running on a *nix machine.

h2opredictordevelopment/predictor/h2o/wrapper.py

From
classpath_arg = ‘.;./’ + jar_file
To
classpath_arg = ‘’ + jar_file

The main class to start this service is /h2o-model-runner/microservice_flask.py

The command line interface gives options to run the application. Type help for a list of available options. > python microservice_flask.py help usage: microservice_flask.py [-h] [–host HOST] [–settings SETTINGS] [–port PORT]

By default without adding arguments the swagger interface should be available at: http://localhost:8061/v2/

Sample model creation

This is the R Script can generate both H2O and POJO models. The below sample uses the iris dataset that may be found anywhere online or use the one that is built into R.

$ library(h2o)
$ h2o.init()
$
$ iris.hex <- h2o.importFile("iris.csv")
$ iris.gbm <- h2o.gbm(y="species", training_frame=iris.hex, model_id="irisgbm")
$ h2o.download_pojo(model = iris.gbm, path="/home/project/h2o",  get_jar = TRUE)
$ h2o.download_mojo(model=iris.gbm, path="/home/project/h2o", get_genmodel_jar=TRUE)

Testing

The only prerequisite for running testing is installing python and tox. It is recommended to use a virtual environment for running any python application. If using a virtual environment make sure to run “pip install tox” to install it

We use a combination of ‘tox’, ‘pytest’, and ‘flake8’ to test ‘h20-model-runner’. Code which is not PEP8 compliant (aside from E501) will be considered a failing test. You can use tools like ‘autopep8’ to “clean” your code as follows:

$ pip install autopep8
$ cd h2o-model-runner
$ autopep8 -r --in-place --ignore E501 acumo_h2o-model-runner/ test/

Run tox directly:

$ cd h2o-model-runner
$ tox

You can also specify certain tox environments to test:

$ tox -e py34  # only test against Python 3.4
$ tox -e flake8  # only lint code

And finally, you can run pytest directly in your environment (recommended starting place):

$ pytest
$ pytest -s   # verbose output