10

The user tutorial says

Navigate to Data > View All
Choose to filter by the model key
Hit Save Model
Input for path: /data/h2o-training/...
Hit Submit

The problem is that I do not have this menu (H2o, 3.0.0.26, web interface)

Alex Lizz
  • 425
  • 1
  • 8
  • 19
  • The option is there since at least 3.8 (i.e. 10-ish months ago). (The Flow version of save model is very useful, as you can save a snapshot of a model at any time, while it is building, but still leaving it to train some more.) – Darren Cook Jan 12 '17 at 10:57

5 Answers5

6

I am, unfortunately, not familiar with the web interface but I can offer a workaround involving H2O in R. The functions

h2o.saveModel(object, dir = "", name = "", filename = "", force = FALSE)

and

h2o.loadModel(path, conn = h2o.getConnection())

Should offer what you need. I will try to have a look at H2O Flow.

Update

I cannot find the possibility to explicitly save a model either. What you can do instead is save the 'Flow'. You ergo could upload/import your file, build the model and then save / load the status :-)

  • I have some issues with R interface before. I can of course give it another try ... I can save a flow, it is not a problem. But I'd like to be able to save a model. Otherwise something that has been fitting for hour is lost should anything happen to the app, or java, or computer .... The worst thing is that manual has an instruction how to do it, but I can not find these options. Probably the documentation is for a previous version, and something happened in the newer one ... I hoped maybe someone from H2O would comment ... – Alex Lizz Jul 22 '15 at 23:36
3

When viewing the model in H2O Flow, you will see an 'Export' button as an action that can be taken against a model

From there, you will be prompted to specify a path in 'Export Model' dialog. Specify the path and hit the 'Export' button. That will save you model to disk.

I'm referring to H2O version 3.2.0.3

Hank Roark
  • 41
  • 3
1

A working example that I've used recently while building a deep learning model in version 2.8.6 in h2o.The model was saved in hdfs.For latest version you probably have to remove the classification=T switch and have to replace data with training_frame

library(h2o)
h = h2o.init(ip="xx.xxx.xxx.xxx", port=54321, startH2O = F)

cTrain.h2o <- as.h2o(h,cTrain,key="c1")
cTest.h2o <- as.h2o(h,cTest,key="c2")

nh2oD<-h2o.deeplearning(x =c(1:12),y="tgt",data=cTrain.h2o,classification=F,activation="Tanh",
                        rate=0.001,rho=0.99,momentum_start=0.5,momentum_stable=0.99,input_dropout_ratio=0.2,                        
                        hidden=c(12,25,11,11),hidden_dropout_ratios=c(0.4,0.4,0.4,0.4),
                        epochs=150,variable_importances=T,seed=1234,reproducible = T,l1=1e-5,
                        key="dn")

hdfsdir<-"hdfs://xxxxxxxxxx/user/xxxxxx/xxxxx/models"

h2o.saveModel(nh2oD,hdfsdir,name="DLModel1",save_cv=T,force=T)

test=h2o.loadModel(h,path=paste0(hdfsdir,"/","DLModel1"))
0xF
  • 546
  • 4
  • 20
1

This should be what you need:

library(h2o)
h2o.init()
path = system.file("extdata", "prostate.csv", package = "h2o")
h2o_df = h2o.importFile(path)
h2o_df$CAPSULE = as.factor(h2o_df$CAPSULE)
model = h2o.glm(y = "CAPSULE",
              x = c("AGE", "RACE", "PSA", "GLEASON"),
              training_frame = h2o_df,
              family = "binomial")
h2o.download_pojo(model)

http://h2o-release.s3.amazonaws.com/h2o/rel-slater/5/docs-website/h2o-docs/index.html#POJO%20Quick%20Start

Frank B.
  • 1,813
  • 5
  • 24
  • 44
  • The pojo of the model is not sufficient to re-import back in to H2O later. – matt2000 Mar 02 '16 at 07:06
  • In that case you have to save the model in binary format. So that in future you can load it again. But the down side of the binary format is that it is version dependent. – kamran kausar Dec 19 '18 at 07:01
1

How to save models in H2O Flow:

  1. go to "List All Models"

  2. in the model details, you will find an "Export" option

  3. enter the model name you want to save it as
  4. import it back again

How to save a model trained in h2o-py:

# say "rf" is your H2ORandomForestEstimator object. To export it
>>> path = h2o.save_model(rf, force=True) # save_model() returns the path
>>> path
u'/home/user/rf'

#to import it back again(as a new object)
>>> rafo = h2o.load_model(path)
>>> rafo   # prints model details
Model Details
=============
H2ORandomForestEstimator :  Distributed Random Forest
Model Key:  drf1
Model Summary:
######Prints model details...................
Hng
  • 148
  • 4