Scoring with H2O MOJO model at command line with Java

If you are using H2O MOJO model you can use that to scoring in python or any other language just by using java runtime. This is a quick hack way to do the scoring on command line or from Python. Here are few example:

What you will have:

  • H2O MOJO model (it will be i.e.
  • H2O supported class file for scoring i.e.  h2o-genmodel.jar
  • Your data set in JSON format to score i.e. ‘{“AGE”:”68″,”RACE”:”2″, “DCAPS”:”2″, “VOL”:”0″,”GLEASON”:”6″ }’


Here is command line way to perform scoring:

$ java -Xmx4g -cp .:/Users/avkashchauhan/src/ water.util.H2OPredictor /Users/avkashchauhan/src/ ‘{\”AGE\”:\”68\”, \”RACE\”:\”2\”, \”DCAPS\”:\”2\”, \”VOL\”:\”0\”,\”GLEASON\”:\”6\” }’

Here is the results of above command:


Here is python code to score by launch external Java process:

> import subprocess

> gen_model_arg = ‘.:/Users/avkashchauhan/src/’> h2o_predictor_class = ‘water.util.H2OPredictor’
> mojo_model_args = ‘/Users/avkashchauhan/src/’
> json_data = {“AGE”:”68″,”RACE”:”2″, “DCAPS”:”2″, “VOL”:”0″,”GLEASON”:”6″}

Calling subprocess module:

> output = subprocess.check_output([“java” , “-Xmx4g”, “-cp”, gen_model_arg, h2o_predictor_class,
mojo_model_args, json_data], shell=False).decode()

## Generating output

> output

u'[ {"labelIndex":0,"label":"0",

Thats it, enjoy!!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s