如何使用Python从H2O生成和保存POJO [英] How to generate and save POJO from H2O using Python

查看:259
本文介绍了如何使用Python从H2O生成和保存POJO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Python在H2O中创建的模型.我想生成该模型的POJO并保存.

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

说我的模型叫做model_rf.

Say my model is called model_rf.

我尝试过:

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

这将创建一个名为"pojo_test"的目录,其中包含一堆二进制文件.我想要一个Java文件,例如model_rf.java,它就是POJO本身.

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.

我尝试过:

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

哪个给出了错误消息:

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.

推荐答案

一切看起来都很好,就像您需要更改使用的path一样.

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

不要使用h2o.save_model创建的目录,而要使用一个已知的目录并且知道该目录的路径.作为第一个测试,您可以将其保存到桌面上,例如使用

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)

您需要替换your_user_name的位置(假设您使用的是Mac)

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

以下是您可以从头尝试的示例(首先使用h2o.cluster().shutdown()

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)

再次需要替换your_user_name的地方(这是假设您使用的是Mac)

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

(可能发生的情况:好像是第一次使用h2o.save_model将H2O模型保存到磁盘时,在运行原始h2o群集的位置创建了一个目录(检查是否要连接到h2o群集来自不同位置),第二次尝试使用download_pojo保存模型时,它查看了当前目录,发现那里不存在'pojo_test2'.

(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.

当您运行h2o.save_model时,它将打印出创建新目录的完整路径.查看该路径是否与当前目录相同.

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.

这篇关于如何使用Python从H2O生成和保存POJO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆