How to generate and save POJO from H2O using Python

妖精的绣舞 提交于 2019-12-08 13:20:39

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/39128865/how-to-generate-and-save-pojo-from-h2o-using-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!