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.