如何在H2o中保存/加载训练有素的模型?

时间:2015-07-20 17:10:11

标签: h2o

用户教程说

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

问题是我没有这个菜单(H2o,3.0.0.26,web界面)

5 个答案:

答案 0 :(得分:5)

不幸的是,我不熟悉网络界面,但我可以在R中提供涉及H2O的解决方法。函数

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

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

应该提供您所需要的。我将尝试看看H2O Flow。

<强>更新

我找不到明确保存模型的可能性。你可以做的是保存&#39; Flow&#39;。您可以上传/导入您的文件,构建模型,然后保存/加载状态: - )

答案 1 :(得分:2)

在H2O Flow中查看模型时,您会看到&#39;导出&#39;按钮作为可以对模型采取的动作

从那里,系统将提示您在“导出模型”中指定路径。对话。指定路径并点击“导出”按钮。按钮。这样可以将模型保存到磁盘。

我指的是H2O版本3.2.0.3

答案 2 :(得分:1)

我在h2o版本2.8.6中构建深度学习模型时最近使用的一个工作示例。该模型保存在hdf中。对于最新版本,您可能必须删除分类= T开关并且具有用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"))

答案 3 :(得分:1)

这个应该是你需要的:

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

答案 4 :(得分:1)

如何在H2O Flow中保存模型:

  1. 转到“列出所有型号”

  2. 在模型详细信息中,您将找到“导出”选项

  3. enter the model name you want to save it as
  4. import it back again
  5. 如何保存以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...................