我可以保存H2O模型,再次加载它然后显示它......
# save the model
model_path_2 = h2o.save_model(model=my_xgboost_2, path="tmp/mymodel", force=True)
print (model_path_2)
>>>/home/dell/Documents/Enigma/tmp/mymodel/XGBoost_model_python_1503367354328_27
# load the model
saved_model_2 = h2o.load_model(model_path_2)
但我不能用它来预测。
saved_model_2.predict(test)
>>>xgboost prediction progress: | (failed)
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-100-fa76fd498ee6> in <module>()
----> 1 saved_model_2.predict(test)
/home/dell/anaconda3/lib/python3.6/site-packages/h2o/model/model_base.py in predict(self, test_data)
130 j = H2OJob(h2o.api("POST /4/Predictions/models/%s/frames/%s" % (self.model_id, test_data.frame_id)),
131 self._model_json["algo"] + " prediction")
--> 132 j.poll()
133 return h2o.get_frame(j.dest_key)
134
/home/dell/anaconda3/lib/python3.6/site-packages/h2o/job.py in poll(self, verbose_model_scoring_history)
75 if (isinstance(self.job, dict)) and ("stacktrace" in list(self.job)):
76 raise EnvironmentError("Job with key {} failed with an exception: {}\nstacktrace: "
---> 77 "\n{}".format(self.job_key, self.exception, self.job["stacktrace"]))
78 else:
79 raise EnvironmentError("Job with key %s failed with an exception: %s" % (self.job_key, self.exception))
OSError: Job with key $03017f00000132d4ffffffff$_927b7278904ecf169173d48a23de4c10 failed with an exception: java.lang.NullPointerException
stacktrace:
java.lang.NullPointerException
但是,我可以预测模型而不保存它。我在Ubuntu 16.04上使用Python 3.6.1和H2O 3.14.0.1。