Using H2O with Java

1,628 views
Skip to first unread message

Thushan Ganegedara

unread,
Jun 21, 2015, 7:36:10 PM6/21/15
to h2os...@googlegroups.com
Hi,

I am quite new to H2O and I would like to know few things about using H2O with Java.

I read few posts related to my issue

However, I'm still not clear about how to use H2O with Java.

What I could figure out from the above threads was that I should call the REST API via Java to run the algorithms. Is there a proper example which explains how to use the REST API?

Thank you very much

rp...@0xdata.com

unread,
Jun 22, 2015, 3:24:24 PM6/22/15
to h2os...@googlegroups.com, thu...@gmail.com
On Sunday, June 21, 2015 at 4:36:10 PM UTC-7, Thushan Ganegedara wrote:
However, I'm still not clear about how to use H2O with Java.

What I could figure out from the above threads was that I should call the REST API via Java to run the algorithms. Is there a proper example which explains how to use the REST API?

Thrushan, thanks for the question!

There are two ways to use H2O with Java.  The simplest is to call the REST API from your Java program to a remote cluster.  This is what 95% of the Java users will do.  The second is to embed H2O within your Java application.  This is what Sparkling Water does.  In this thread I'll talk about the former.  If you're interested in the latter we can open up another topic and point you at the docs for it.

There's a very recent thread in this group on using the REST API from Java.  The subject is "Java API for interacting with remote cluster?"  That will get you going on the mechanics.  Note that I have some slight tweaks to make for the POJO generation, which I'll be doing in the next few days.  You'll use the POJOs from the REST client of your choice.  There are many to choose from in the Java world.  I will add a generated proxy using the Retrofit client in the next week or two.


As for how to use the REST API, there are two pieces: documentation and examples.

Documentation is most easily accessed via Flow.  In the help pane on the bottom you'll see links for docs the endpoints and schemas.  You can also access the same information on the website.  For example, the last stable build, shannon-22, has its docs here: 


We don't have specific examples of using the REST API yet, but Flow, R and Python all use it.  Each step in Flow, for example, translates into one or a very small number of REST API calls.  The script fragments you see of the Flow cells are essentially the payloads for the REST API calls.  Likewise, most R and Python API calls translate directly into a single REST API call.

I'd begin by looking at those docs and playing around with Flow.  I'll be happy to answer any specific questions here.

Thanks!

Tom Kraljevic

unread,
Jun 22, 2015, 6:30:03 PM6/22/15
to rp...@0xdata.com, h2ostream, thu...@gmail.com, Jessica Lanford
>
> We don't have specific examples of using the REST API yet, but Flow, R and Python all use it. Each step in Flow, for example, translates into one or a very small number of REST API calls. The script fragments you see of the Flow cells are essentially the payloads for the REST API calls. Likewise, most R and Python API calls translate directly into a single REST API call.
>

(+ Jessica)


Two good ways to see the REST API in action:


1. Use Chrome. Open the developer tab. Open a web page to the Flow UI. Do stuff. Look at the network calls made by flow.


2. Write an R program for H2O using the H2O R package.
Call h2o.startLogging() at the beginning of your package.
This puts all the REST API transactions into a log file.


Thanks,
Tom


Thushan Ganegedara

unread,
Jun 22, 2015, 6:54:25 PM6/22/15
to h2os...@googlegroups.com, thu...@gmail.com
Hello Raymond and Tom, 

Thank you very much for the detailed answer

There are two ways to use H2O with Java.  The simplest is to call the REST API from your Java program to a remote cluster.  This is what 95% of the Java users will do.  The second is to embed H2O within your Java application.  This is what Sparkling Water does.  In this thread I'll talk about the former.  If you're interested in the latter we can open up another topic and point you at the docs for it.
Yes, I'd be happy to open up a new thread and discuss about this too.

There's a very recent thread in this group on using the REST API from Java.  The subject is "Java API for interacting with remote cluster?"  That will get you going on the mechanics.  Note that I have some slight tweaks to make for the POJO generation, which I'll be doing in the next few days.  You'll use the POJOs from the REST client of your choice.  There are many to choose from in the Java world.  I will add a generated proxy using the Retrofit client in the next week or two.
Yes, thank you very much for pointing me to this thread. I will have a look. However, I stumbled upon the java tests given here h2o-3/h2o-algos/src/test/java/hex/deeplearning/DeepLearningMNIST.java  (github) And using the tests given there, I was able to run a deep learning model on MNIST dataset. I have attached the log file created in the IDE herewith. Seems it is working really well. Is this a legitimate way of doing it, rather than calling the REST API directly?

I'd begin by looking at those docs and playing around with Flow.
Thank you very much for the suggestion. Yes. I'll start by looking at the docs and playing around with Flow

Two good ways to see the REST API in action: 


1.  Use Chrome.  Open the developer tab.  Open a web page to the Flow UI.  Do stuff.  Look at the network calls made by flow. 


2.  Write an R program for H2O using the H2O R package. 
     Call h2o.startLogging() at the beginning of your package. 
     This puts all the REST API transactions into a log file. 
I think I'll go with the first method as I'm not very competent with R. However, I have started playing with the python package too. So hopefully using the Web UI and python package, it'll be possible to figure out.

Thank you very much again for the detailed walkthrough, explanations and references given regarding the issue.
log_h2o.txt

Thushan Ganegedara

unread,
Jun 22, 2015, 6:59:35 PM6/22/15
to h2os...@googlegroups.com
Hello Raymond and Tom, 

I'm reposting my reply as it is unclear in the above reply. Sorry about the inconvenience. 

Thank you very much for the detailed answer.

There are two ways to use H2O with Java.  The simplest is to call the REST API from your Java program to a remote cluster.  This is what 95% of the Java users will do.  The second is to embed H2O within your Java application.  This is what Sparkling Water does.  In this thread I'll talk about the former.  If you're interested in the latter we can open up another topic and point you at the docs for it.

Yes, I'd be happy to open up a new thread and discuss about this too.


There's a very recent thread in this group on using the REST API from Java.  The subject is "Java API for interacting with remote cluster?"  That will get you going on the mechanics.  Note that I have some slight tweaks to make for the POJO generation, which I'll be doing in the next few days.  You'll use the POJOs from the REST client of your choice.  There are many to choose from in the Java world.  I will add a generated proxy using the Retrofit client in the next week or two.

Yes, thank you very much for pointing me to this thread. I will have a look. However, I stumbled upon the java tests given here h2o-3/h2o-algos/src/test/java/hex/deeplearning/DeepLearningMNIST.java  (github) And using the tests given there, I was able to run a deep learning model on MNIST dataset. I have attached the log file created in the IDE herewith. Seems it is working really well. Is this a legitimate way of doing it, rather than calling the REST API directly?


I'd begin by looking at those docs and playing around with Flow.
Thank you very much for the suggestion. Yes. I'll start by looking at the docs and playing around with Flow


Two good ways to see the REST API in action: 
1.  Use Chrome.  Open the developer tab.  Open a web page to the Flow UI.  Do stuff.  Look at the network calls made by flow. 
2.  Write an R program for H2O using the H2O R package. 
     Call h2o.startLogging() at the beginning of your package. 
     This puts all the REST API transactions into a log file. 


I think I'll go with the first method as I'm not very competent with R. However, I have started playing with the python package too. So hopefully using the Web UI and python package, it'll be possible to figure out.

Thank you very much again for the detailed walkthrough, explanations and references given regarding the issue.


log_h2o.txt

Tom Kraljevic

unread,
Jun 22, 2015, 7:55:27 PM6/22/15
to Thushan Ganegedara, h2os...@googlegroups.com
Yes, thank you very much for pointing me to this thread. I will have a look. However, I stumbled upon the java tests given here h2o-3/h2o-algos/src/test/java/hex/deeplearning/DeepLearningMNIST.java  (github) And using the tests given there, I was able to run a deep learning model on MNIST dataset. I have attached the log file created in the IDE herewith. Seems it is working really well. Is this a legitimate way of doing it, rather than calling the REST API directly?

Yes, this is definitely a legitimate way to do it.


Thushan Ganegedara

unread,
Jun 22, 2015, 7:58:56 PM6/22/15
to Tom Kraljevic, h2os...@googlegroups.com
Hello Tom,

Thank you very much for the clarification

On Tue, Jun 23, 2015 at 9:55 AM, Tom Kraljevic <to...@h2o.ai> wrote:
Yes, thank you very much for pointing me to this thread. I will have a look. However, I stumbled upon the java tests given here h2o-3/h2o-algos/src/test/java/hex/deeplearning/DeepLearningMNIST.java  (github) And using the tests given there, I was able to run a deep learning model on MNIST dataset. I have attached the log file created in the IDE herewith. Seems it is working really well. Is this a legitimate way of doing it, rather than calling the REST API directly?

Yes, this is definitely a legitimate way to do it.





--
Regards,

Thushan Ganegedara
School of IT
University of Sydney, Australia

rp...@0xdata.com

unread,
Jun 22, 2015, 8:45:05 PM6/22/15
to h2os...@googlegroups.com, to...@h2o.ai, thu...@gmail.com
On Monday, June 22, 2015 at 4:55:27 PM UTC-7, Tom Kraljevic wrote:
Yes, thank you very much for pointing me to this thread. I will have a look. However, I stumbled upon the java tests given here h2o-3/h2o-algos/src/test/java/hex/deeplearning/DeepLearningMNIST.java  (github) 
Yes, this is definitely a legitimate way to do it.

Note that those tests are JUnit.  The way they call the Java API is the way you would call directly from any Java. However, if you go this route you either would want to fork and modify H2OApp.java, or follow the instructions for using H2O as a Maven dependency:


and click the Use From Maven tab.  You can also look at the h2o-app subproject in the source tree, or the droplets docs.  There's more info here:


and here:



I'd proceed with some caution right now in using the Python binding to understand the REST API.  It uses heavy use of the Rapids expression language (endpoint /99/Rapids), which is going through heavy change right now.  The import / model build / predict stuff pieces stable hit stable /3 APIs, but if you want to do data manipulation you should use the Python or R packages rather than trying to use Rapids.

Thushan Ganegedara

unread,
Jun 25, 2015, 3:01:02 AM6/25/15
to h2os...@googlegroups.com, thu...@gmail.com, to...@h2o.ai
Hello Raymond,

Thank you very much for the resources and the tips. Highly appreciate them

Thushan Ganegedara

unread,
Jun 28, 2015, 6:35:24 AM6/28/15
to h2os...@googlegroups.com

Hello,

H2O looks quite promising and I'm really happy with it's performance. However, I would be very grateful if you could clarify one thing.

Can I send data in the code itself (hard-coded), rather than sending them as a CSV file, to the algorithm? Is that possible?

Your help will be highly appreciated.

Thank you

Tom Kraljevic

unread,
Jun 28, 2015, 9:08:50 AM6/28/15
to Thushan Ganegedara, h2os...@googlegroups.com

Hi

Theoretically the answer is yes...  But it may or may not be practical/possible...  depends on the environment you are talking about.

What language are you using and how much data do you have?

Do you want to do this for convenience or performance reasons?

Tom

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.

Thushan Ganegedara

unread,
Jun 28, 2015, 4:41:31 PM6/28/15
to Tom Kraljevic, h2os...@googlegroups.com
Hello Tom,

Thank you very much for the quick response

What language are you using and how much data do you have?

I'm writing in Java. And data is relatively small (e.g. 50000 cases of MNIST dataset)

Do you want to do this for convenience or performance reasons?

I'm doing this to maintain consistency. I have several other classifiers and and they all implement a method called train(JavaRDD<LabeledPoints> training data) JavaRDD is an apache spark utility class. So it would be great if I could implement the training process for H2O deep learning using the data itself, than reading from file.

Thank you 

Tom Kraljevic

unread,
Jun 28, 2015, 4:49:04 PM6/28/15
to Thushan Ganegedara, Tom Kraljevic, h2os...@googlegroups.com

If you are already using spark, then you could try sparkling water and just use a line of scala to copy the spark rdd into an h2o rdd, and call h2o algorithms from there.


Here are some resources to look at:

(Reachable from http://h2o.ai/download)


Tom

Thushan Ganegedara

unread,
Jun 28, 2015, 6:49:55 PM6/28/15
to Tom Kraljevic, Tom Kraljevic, h2os...@googlegroups.com
Hello Tom,

That sounds like a better way to what I'm trying to do. I'll try it and let you know how it goes.

Thank you very much for the prompt help 

Michal Malohlava

unread,
Jun 28, 2015, 9:26:41 PM6/28/15
to h2os...@googlegroups.com
Hi Thushan,

you can take the RDD and publish it in H2O and run model builder on it.

Look also here: https://github.com/h2oai/sparkling-water/blob/master/DEVEL.md

michal

Dne 6/28/15 v 3:49 PM Thushan Ganegedara napsal(a):

Thushan Ganegedara

unread,
Jun 30, 2015, 8:09:34 PM6/30/15
to h2os...@googlegroups.com, mic...@h2oai.com
Dear Michal,

Thank you very much. Yes, that seems like a nice way of doing it. I am looking into it currently. I highly appreciate your help regarding the matter.

Thushan Ganegedara

unread,
Jun 30, 2015, 8:16:51 PM6/30/15
to h2os...@googlegroups.com

Dear all,

I was doing some tests with H2O and now everything seems to be working well. I am currently using the file to read to H2O but I am looking into how to pass a JavaRDD to H2O.

However, I stumbled upon a new issue

I retrieved the DeeplearningModel after training the Model on data.

    model = dl.trainModel().get();

Then I serialized the model using
    FileOutputStream fout = new FileOutputStream("dl.ser");
    ObjectOutputStream oos = new ObjectOutputStream(fout);
    oos.writeObject(model);

Then I tried deserializing the model using
    InputStream fin = new FileInputStream("dl.ser");
    InputStream buffer = new BufferedInputStream(fin);
    ObjectInput input = new ObjectInputStream (buffer);
    DeepLearningModel model2 = (DeepLearningModel) input.readObject();

I get the following error during the deserialization process

java.io.InvalidClassException: hex.deeplearning.DeepLearningModel; no valid constructor
at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:150)
at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:768)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1775)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at Test.main(Test.java:171)
java.lang.RuntimeException: java.io.InvalidClassException: hex.deeplearning.DeepLearningModel; no valid constructor
at Test.main(Test.java:178)
Caused by: java.io.InvalidClassException: hex.deeplearning.DeepLearningModel; no valid constructor
at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:150)
at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:768)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1775)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at Test.main(Test.java:171)
Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: java.io.InvalidClassException: hex.deeplearning.DeepLearningModel; no valid constructor
at Test.main(Test.java:191)
Caused by: java.lang.RuntimeException: java.io.InvalidClassException: hex.deeplearning.DeepLearningModel; no valid constructor
at Test.main(Test.java:178)
Caused by: java.io.InvalidClassException: hex.deeplearning.DeepLearningModel; no valid constructor
at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:150)
at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:768)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1775)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at Test.main(Test.java:171)

Any idea that helps solving this will be highly appreciated. Thank you

Tom Kraljevic

unread,
Jun 30, 2015, 9:48:49 PM6/30/15
to Thushan Ganegedara, h2os...@googlegroups.com

Hi Thushan,


The R code that calls h2o.saveModel() ends up in this call in ModelsHandler.java.
I don’t expect calling writeObject in the way you showed below would work, the serialization is custom.

(Also see the corresponding importModel in the java code.)


Thanks,
Tom

public ModelExportV3 exportModel(int version, ModelExportV3 mexport) {
Model model = getFromDKV("model_id", mexport.model_id.key());
List<Key> keysToExport = new LinkedList<>();
keysToExport.add(model._key);
keysToExport.addAll(model.getPublishedKeys());

try {
new ObjectTreeBinarySerializer().save(keysToExport, FileUtils.getURI(mexport.dir));
} catch (IOException e) {
throw new H2OIllegalArgumentException("dir", "exportModel", e);
}
return mexport;
}

Thushan Ganegedara

unread,
Jun 30, 2015, 9:55:50 PM6/30/15
to Tom Kraljevic, h2os...@googlegroups.com
Hello Tom,

Thank you very much for the prompt response. If that's the case, I'll implement it as given in the exportModel and importModel methods.

Thank you

Michal Malohlava

unread,
Jun 30, 2015, 10:55:39 PM6/30/15
to h2os...@googlegroups.com
Hi Thushan,

just commenting Tom's response:
 - each iced object implements Serializable interface but its implementation delegates to internally generated serialization code. It should not be used now directly (it is still opened improvement)

 - as tom proposed the best way is to use SaveModel call - just create a serializer and pass a list of keys to it - it will save a model and its dependencies into a given folder.

michal

Dne 6/30/15 v 5:16 PM Thushan Ganegedara napsal(a):

Thushan Ganegedara

unread,
Jun 30, 2015, 11:20:20 PM6/30/15
to h2os...@googlegroups.com, mic...@h2oai.com
Dear Michal,

Thank you very much for the suggestions. Yes, I'll implement it as you suggested.

Thank you very much!
...

Thushan Ganegedara

unread,
Jul 5, 2015, 8:24:37 PM7/5/15
to h2os...@googlegroups.com
Dear all,

Now it is possible to save a deeplearning model and retrieve it as you've suggested. Thank you very much.

However, I've run into a new issue. According to my requirements I need to run deeplearning tasks on H2O on the go (That is if someone submit a job, H2O server should start and run the job). 
However, after running a single job, if I try to run a new job, it says that " Cannot add more Requests once the list is finalized "

I went and looked at the code. and I assume this is happening because of the H2O.finalizeRegistration() method in https://github.com/h2oai/h2o-3/blob/master/h2o-app/src/main/java/water/H2OApp.java

Is there a workaround for this?

I tried shutting down the server and starting again. But shutting down the H2O server, causes the main server (which runs H2O inside) to shutdown too.

Any help would be appreciated.

Thank you

Tom Kraljevic

unread,
Jul 5, 2015, 10:49:19 PM7/5/15
to Thushan Ganegedara, h2os...@googlegroups.com

hi thushan,

instead of starting a new h2o for each request, i recommend you start it once and submit new requests as they arrive.
this is the only model that is supported.

i suppose you *could* try to start a new h2o on each request in a new classloader, but that’s not tested at all… and there is no good way to shut them down.

tom

Thushan Ganegedara

unread,
Jul 5, 2015, 11:46:15 PM7/5/15
to h2os...@googlegroups.com, Tom Kraljevic
Hello Tom,

Thank you very much for the explanation and suggestion. I tried that too. However, I get the following error. 
Cannot add more Requests once the list is finalized "

I tried many different things and searched internet to get around this error. But I couldn't find a solution

Tom Kraljevic

unread,
Jul 6, 2015, 12:03:48 AM7/6/15
to Thushan Ganegedara, h2os...@googlegroups.com

OK, I suggest you collect a stack trace from the spot where that error is printed and share it.

Thushan Ganegedara

unread,
Jul 6, 2015, 12:27:52 AM7/6/15
to h2os...@googlegroups.com, Tom Kraljevic
Hello Tom,

Here's the stack trace

Caused by: java.lang.IllegalArgumentException: Cannot add more Requests once the list is finalized
        at water.H2O.registerPOST(H2O.java:941)
        at water.H2OApp.register(H2OApp.java:40)
        at water.H2OApp.driver(H2OApp.java:29)
        at water.H2OApp.main(H2OApp.java:21)
        at org.wso2.carbon.ml.core.spark.algorithms.StackedAutoencodersClassifier.startH2O(StackedAutoencodersClassifier.java:53)
        at org.wso2.carbon.ml.core.spark.algorithms.StackedAutoencodersClassifier.test(StackedAutoencodersClassifier.java:177)
        at org.wso2.carbon.ml.core.spark.algorithms.DeeplearningModel.buildDeepLearningModel(DeeplearningModel.java:125)

On Monday, July 6, 2015 at 12:49:19 PM UTC+10, Tom Kraljevic wrote:

Tom Kraljevic

unread,
Jul 6, 2015, 12:58:35 AM7/6/15
to Thushan Ganegedara, h2ostream

water.H2OApp.main() starts H2O.
You should only call that once, at the beginning of your main class.

Michal Malohlava

unread,
Jul 6, 2015, 8:12:24 AM7/6/15
to h2os...@googlegroups.com
Hi Thushan,

look into H2OApp implementation:

// Fire up the H2O Cluster
H2O.main(args);

// Register REST API
register(relativeResourcePath);
H2O.finalizeRegistration();

And call it similar code in your app but before the finalizeRegistration call, register your call.

michal

Dne 7/6/15 v 6:58 AM Tom Kraljevic napsal(a):

Thushan Ganegedara

unread,
Jul 6, 2015, 9:14:34 PM7/6/15
to h2os...@googlegroups.com, mic...@h2oai.com
Thank you very much Tom and Michal,

I think putting it on the main class and calling it once will do the trick. Thank you again
...

shahroz...@gmail.com

unread,
Jul 22, 2015, 6:07:01 AM7/22/15
to H2O Open Source Scalable Machine Learning - h2ostream, mic...@h2oai.com
hi everyone
I'm a new user of h2o or should i say sparklingwater. I hope someone here would be able to help me. I am using scala to save and load k-means model of h2o. i also tried to use serialization and deserialization and got "invalidclassexception no constructor found" error. Then i tried to use those importmodel and exportmodel methods but i have run into a problem. See importmodel is returning an instance of ModelsV3 but ModelsV3 is not visible. Can you tell me how can i create object of type ModelsV3 so that i can implement importmodel. and it would be really really helpful if you guys can point me or tell me how to load and save h2o models using scala. I'm really having difficulty implementing that.
thanks

shahroz...@gmail.com

unread,
Jul 22, 2015, 8:53:24 AM7/22/15
to H2O Open Source Scalable Machine Learning - h2ostream, mic...@h2oai.com
i tried to create an object of ModelsHandler but i am gettinh this error
"class ModelsHandler in package api cannot be accessed in package water.api"

can anyone tel me how can i now use importmodel and exportmodel methods so that i can save and load these models??

Thanks

Michal Malohlava

unread,
Jul 22, 2015, 2:42:34 PM7/22/15
to shahroz...@gmail.com, H2O Open Source Scalable Machine Learning - h2ostream
Hello,

thank you for trying Sparkling Water!

To use (de-)serialization code please look into ModelsHandler how to use Java API directly. ModelsV3 is a representation of end-point, you should not use it directly.

https://github.com/h2oai/h2o-3/blob/master/h2o-core/src/main/java/water/api/ModelsHandler.java#L181-L208

For example, model import can be implemented in the following way:
  List<Key> importedKeys = new ObjectTreeBinarySerializer().load(FileUtils.getURI(mimport.dir));
  Model model = (Model) importedKeys.get(0).get();

michal


Dne 7/22/15 v 3:07 AM shahroz...@gmail.com napsal(a):

Michal Malohlava

unread,
Jul 22, 2015, 2:47:49 PM7/22/15
to shahroz...@gmail.com, H2O Open Source Scalable Machine Learning - h2ostream
Hello,

please see my previous e-mail. Handlers are designed to handle REST API requests.

You should use:

List<Key> importedKeys = new ObjectTreeBinarySerializer().load(FileUtils.getURI(mimport.dir));
  Model model = (Model) importedKeys.get(0).get();


michal


Dne 7/22/15 v 5:53 AM shahroz...@gmail.com napsal(a):

shahroz...@gmail.com

unread,
Jul 23, 2015, 1:54:16 AM7/23/15
to H2O Open Source Scalable Machine Learning - h2ostream, mic...@h2oai.com, mic...@h2o.ai
Thanks Michal. But sorry i am new and still facing some problems. What i want to do is i want to train H2o models, then save those models and then load those saved models to score (or use prediction) on other datasets. and i want to do this on scala. now can you pleas tell me how can i do this.

what i am currently doing is this.
I have trained a k-means model and then saved that model using serialization, but on deserialization i got "invalidclassexception, no valid contructor" error. I then tried using objectbinaryserialization to save model but when io loaded that model then all i got was the model key. i mean that loaded thing was not able to call "score" function of k-means.
Now is there any way? how can i load a model which can be used to score ??
Regards

Michal Malohlava

unread,
Jul 23, 2015, 3:41:30 PM7/23/15
to shahroz...@gmail.com, H2O Open Source Scalable Machine Learning - h2ostream, mic...@h2o.ai
Dne 7/22/15 v 10:54 PM shahroz...@gmail.com napsal(a):
> Thanks Michal. But sorry i am new and still facing some problems. What i want to do is i want to train H2o models, then save those models and then load those saved models to score (or use prediction) on other datasets. and i want to do this on scala. now can you pleas tell me how can i do this.
>
> what i am currently doing is this.
> I have trained a k-means model and then saved that model using serialization, but on deserialization i got "invalidclassexception, no valid contructor" error.
We do not support normal Java serialization/deserialization.
> I then tried using objectbinaryserialization to save model but when io loaded that model then all i got was the model key. i mean that loaded thing was not able to call "score" function of k-means.
yeah, if you have model key, you have a model - the key represents a reference to a model.

val model: KMeansModel = modelKey.get

or
val model: KMeansModel = DKV.get(modelKey)


Michal

shahroz...@gmail.com

unread,
Jul 25, 2015, 3:10:28 PM7/25/15
to H2O Open Source Scalable Machine Learning - h2ostream, mic...@h2o.ai, mic...@h2oai.com
Thanks Michal. i was using k-means model and i was able to load it successfully using
val model: KMeansModel = modelKey.get

but this "val model: KMeansModel = DKV.get(modelKey)" didnt work.
Anyways thanks for helping. I actually plan to save and load all h2o models using sparklingwater so i hope you'll be able to help me in future again.

Michal Malohlava

unread,
Jul 27, 2015, 2:26:28 PM7/27/15
to shahroz...@gmail.com, H2O Open Source Scalable Machine Learning - h2ostream, mic...@h2o.ai
Dne 7/25/15 v 12:10 PM shahroz...@gmail.com napsal(a):
> Thanks Michal. i was using k-means model and i was able to load it successfully using
> val model: KMeansModel = modelKey.get
Nice!
>
> but this "val model: KMeansModel = DKV.get(modelKey)" didnt work.
Sorry, my fault: you can do : DKV.getGet(modelKey), or DKV.get(modelKey).get() (do not forget null
check after first get)
Explanation: DKV.get(modelKey) returns untyped Value, which needs to be converted to an actual type
by additional get call

michal
Reply all
Reply to author
Forward
0 new messages