python 导入模型h20_如何使用Python从H2O生成和保存POJO

I have a model created in H2O using Python. I want to generate a POJO of that model, and save it.

Say my model is called model_rf.

I have tried:

h2o.save_model(model_rf, path='./pojo_test', force=False)

This create a directory called "pojo_test", which contains a whole bunch of binary files. I want a java file though, something like model_rf.java, that is the POJO itself.

I tried:

h2o.download_pojo(model_rf, path='./pojo_test_2', get_jar = True)

Which gave the error message:

IOError: [Errno 2] No such file or directory: u'./pojo_test_2/model_rf.java'

What am I missing? Probably a stupid question but I cannot for the life of me figure this out.

解决方案

Everything looks fine, it just looks like you need to change the path you used.

Instead of using the directory that h2o.save_model created, use a directory that you know exists and for which you know the path. As a first test you could just save to your desktop, for example use

h2o.download_pojo(model_rf, path = '/Users/your_user_name/Desktop/', get_jar = True)

where you need to replace your_user_name (this is assuming you are using a mac)

Here's an example you can try from scratch (shutdown h2o first with h2o.cluster().shutdown()

import h2o

h2o.init()

iris_df = h2o.import_file("https://s3.amazonaws.com/h2o-public-test-data/smalldata/iris/iris.csv")

from h2o.estimators.glm import H2OGeneralizedLinearEstimator

predictors = iris_df.columns[0:4]

response_col = "C5"

train,valid,test = iris_df.split_frame([.7,.15], seed =1234)

glm_model = H2OGeneralizedLinearEstimator(family="multinomial")

glm_model.train(predictors, response_col, training_frame = train, validation_frame = valid)

h2o.download_pojo(glm_model, path = '/Users/your_user_name/Desktop/', get_jar = True)

again where you need to replace your_user_name (this is assuming you are using a mac)

(what might have happened: It looks like the first time you saved an H2O model to disk with h2o.save_model a directory was created in the location you were running your original h2o cluster (check if you are connecting to an h2o cluster from different locations) and the second time you tried to save the model with download_pojo it looked at your current directory and saw that 'pojo_test2' didn't exist there.

when you run h2o.save_model it will print out the full path to where it created a new directory. See if that path is the same as your current directory.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值