How to make real time predictions using H2O/POJO model

1,937 views
Skip to first unread message

jakob....@vendoservices.com

unread,
Jan 27, 2016, 6:17:25 AM1/27/16
to H2O Open Source Scalable Machine Learning - h2ostream
Hi,

This is my first time using H2O :-)

Goal:
I'm trying to integrate the prediction model on a standalone server in the simplest way possible:
I want to make a prediction based on some parameters.

What I have tried:
- I have already created the model in H2O and it's been trained on historical data.
- I have exported the model into a .java file (is this the POJO?)
- I have tried to follow the instructions included to compile it (something like "javac -cp h2o-genmodel.jar -J-Xmx2g -J-XX:MaxPermSize=128m Model_1.java", which outputs a bunch of .class files)
- I have tried to execute the POJO to get a prediction (something like this walk-trough: http://h2o-release.s3.amazonaws.com/h2o/rel-markov/1/docs-website/userguide/scorePOJO.html)

My questions:
- POJO is which type of file (source code, plain text, archive, executable, other)?
- Which java version is required?
- Do i need the same java version to create the model in H2O, compile it and run it, or it can be different versions?
- Do I need to compile the POJO on the same server that it needs to be executed on?
- How do I simply query a POJO for a prediction?
- Do I need anything else than Java Runtime Environment (JRE) on the server to query a POJO for a prediction?

I feel the documentation on H2O is missing a very simple tutorial for simply doing standalone prediction queries on a H2O model. I do not use Hadoop or Spark and I would like to install as little as possible on the server that will calculate predictions in real time.

Best,
Jakob

Tom Kraljevic

unread,
Jan 27, 2016, 9:37:21 AM1/27/16
to jakob....@vendoservices.com, H2O Open Source Scalable Machine Learning - h2ostream

look here:

h2o.ai/docs

http://h2o-release.s3.amazonaws.com/h2o/rel-tibshirani/8/docs-website/h2o-genmodel/javadoc/index.html

learn.h2o.ai (see building a smarter application)

Sent from my iPhone
> --
> You received this message because you are subscribed to the Google Groups "H2O Open Source Scalable Machine Learning - h2ostream" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to h2ostream+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jakob Givoni

unread,
Jan 27, 2016, 10:08:55 AM1/27/16
to Tom Kraljevic, H2O Open Source Scalable Machine Learning - h2ostream
Unfortunately I have already looked at all that and much more, and it doesn't answer my questions :-(
--
Best,
Jakob Givoni
jakob....@vendostore.com
partner.vendostore.com
Mobile: +34663302753
Skype contact: jakob.vendo

@vendostore

IMPORTANT: This email message is intended only for the use of the individual to whom, or entity to which, it is addressed and may contain information that is privileged, confidential and exempt from disclosure under applicable law.  If you are NOT the intended recipient, you are hereby notified that any use, dissemination, distribution or copying of the communication is strictly prohibited.  If you have received this communication in error, please notify me immediately. Thank you.

Tom Kraljevic

unread,
Jan 27, 2016, 11:22:24 AM1/27/16
to jakob....@vendoservices.com, H2O Open Source Scalable Machine Learning - h2ostream
My questions:
- POJO is which type of file (source code, plain text, archive, executable, other)?

the model is emitted from H2O as java source code.
you would then compile that into class files and potentially package the class files yourself into a jar file if you like.


- Which java version is required?

java 7 or java 8


- Do i need the same java version to create the model in H2O, compile it and run it, or it can be different versions?

it can be different versions, but you probably want to compile to java 7 byte codes for maximum portability.


- Do I need to compile the POJO on the same server that it needs to be executed on?

no.  you can run the pojo anywhere.


- How do I simply query a POJO for a prediction?

From here:

    hex.genmodel.GenModel rawModel;
    rawModel = (hex.genmodel.GenModel) Class.forName(modelClassName).newInstance();
    EasyPredictModelWrapper model = new EasyPredictModelWrapper(rawModel);

    RowData row = new RowData();
    row.put("Year", "1987");
    row.put("Month", "10");
    row.put("DayofMonth", "14");
    row.put("DayOfWeek", "3");
    row.put("CRSDepTime", "730");
    row.put("UniqueCarrier", "PS");
    row.put("Origin", "SAN");
    row.put("Dest", "SFO");

    BinomialModelPrediction p = model.predictBinomial(row);
    System.out.println("Label (aka prediction) is flight departure delayed: " + p.label);
    System.out.print("Class probabilities: ");

The predictBinomial() call.


- Do I need anything else than Java Runtime Environment (JRE) on the server to query a POJO for a prediction?

no


Jakob Givoni

unread,
Jan 27, 2016, 11:34:06 AM1/27/16
to Tom Kraljevic, H2O Open Source Scalable Machine Learning - h2ostream
Thank you Tom. 
Nothing surprising in the answers - it seems I had understood it correctly, so not sure why I couldn't make it work. Will now focus on that example and report back if I encounter any specific problems.
Best,
Jakob

Jakob Givoni

unread,
Jan 27, 2016, 12:51:17 PM1/27/16
to Tom Kraljevic, H2O Open Source Scalable Machine Learning - h2ostream
Ok, follow-ups:
- My model is a GBM, but the prediction is a float, not a simple yes/no. Should I still use predictBinomial or is there another wrapper method, or should I use score0 directly?
- Step 4 - creating the main program: Do I still need H2O at that point or it can be done in a different environment? Which files are needed exactly at this point? Just the POJO and the h2o-genmodel.jar?

Jakob Givoni

unread,
Jan 27, 2016, 1:04:50 PM1/27/16
to Tom Kraljevic, H2O Open Source Scalable Machine Learning - h2ostream
I think I succeeded!

I used:
RegressionModelPrediction p = model.predictRegression(row);
System.out.println("Predicted value: " + p.value);

I compiled with nothing but the h2o-genmodel.jar and the POJO file from H2O.

Thanks for the help!

Michal Malohlava

unread,
Jan 27, 2016, 2:01:41 PM1/27/16
to h2os...@googlegroups.com
Hi Jakob,


On 1/27/16 8:33 AM, Jakob Givoni wrote:
Thank you Tom. 
Nothing surprising in the answers - it seems I had understood it correctly, so not sure why I couldn't make it work.
Did you figure out the problem? If not send here more detailed description/exception.
I would love to help.

Thanks,
Michal

--

Michal Malohlava

unread,
Jan 27, 2016, 2:06:01 PM1/27/16
to h2os...@googlegroups.com
On 1/27/16 9:50 AM, Jakob Givoni wrote:
Ok, follow-ups:
- My model is a GBM, but the prediction is a float, not a simple yes/no. Should I still use predictBinomial or is there another wrapper method, or should I use score0 directly?
Did you train binomial model? If yes, you should use predictBinomial. If your model is regression model, then predictRegression.
You can use score0 directly as well, but score0 is part of low-level api and all inputs have to be prepared in the H2O expected form (e.g., mapping of categorical values to right int numbers)

- Step 4 - creating the main program: Do I still need H2O at that point or it can be done in a different environment? Which files are needed exactly at this point? Just the POJO and the h2o-genmodel.jar?
you need POJO and h2o-genmodel.jar - POJO contains strictly generated code, h2o-genmodel.jar contains support functions (for example, average, scaling of prediction,...)

You can find a simple example here: https://github.com/h2oai/qcon2015/blob/master/06-pojo-model-deployment/ask-craig-pojo-streaming-app/src/main/scala/water/app/AskCraigPojoStreamingApp.scala#L34-L47 (it is in scala, but java API is the same)

michal
--

DEVesh Pawar

unread,
Feb 1, 2016, 9:36:02 AM2/1/16
to H2O Open Source Scalable Machine Learning - h2ostream, mic...@h2oai.com
Hi Michal,

Hi,

I want to use REST api to import and parse file, I am able to do it on http://10.230.17.156:54321/flow/index.html

But how to do it on localhost?

Got the source  : https://github.com/h2oai/h2o-3 

But got lost afterwards, which folder to use, how to import and proceed further.

Thanks for your help.

Dev

Michal Malohlava

unread,
Feb 1, 2016, 4:28:02 PM2/1/16
to DEVesh Pawar, H2O Open Source Scalable Machine Learning - h2ostream
On 2/1/16 6:36 AM, DEVesh Pawar wrote:
Hi Michal,

Hi,

I want to use REST api to import and parse file, I am able to do it on http://10.230.17.156:54321/flow/index.html

But how to do it on localhost?

Got the source  : https://github.com/h2oai/h2o-3
You need to build and launch H2O and then point your browser to localhost:54321

See here: https://github.com/h2oai/h2o-3#4-building-h2o-3

michal

Gabriel Fields

unread,
Jul 8, 2020, 7:31:22 AM7/8/20
to H2O Open Source Scalable Machine Learning - h2ostream
Hi, 

I have a question. 
A quick background on what I did with H2O is that I am able to perform predictions in my own java environment using the MOJO that I downloaded from H2O.

I am planning to use the outputs (Scoring History, Variable Importances, etc) from the model that I built in H2O.


I want to use this data and display with my own development environment. 
However, I can't seem to find any sample that shows this.

I want to ask. Is it possible to retrieve and display this data using the MOJO?
If so, how can I do this? Is there a documentation reference I can look into for this?

Regards,
Gabriel
Reply all
Reply to author
Forward
0 new messages