This section describes how to save and load models using R, Python, and Flow.

Note: When saving an H2O binary model with h2o.saveModel (R), h2o.save_model (Python), or in Flow, you will only be able to load and use that saved binary model with the same version of H2O that you used to train your model. H2O binary models are not compatible across H2O versions. If you update your H2O version, then you will need to retrain your model. For production, you can save your model as a POJO/MOJO. These artifacts are not tied to a particular version of H2O because they are just plain Java code and do not require an H2O cluster to be running.

## In R and Python¶

In R and Python, you can save a model locally or to HDFS using the h2o.saveModel (R) or h2o.save_model (Python) function . This function accepts the model object and the file path. If no path is specified, then the model will be saved to the current working directory. After the model is saved, you can load it using the h2o.loadModel (R) or h2o.load_model (Python) function.

# build the model
model <- h2o.deeplearning(params)

# save the model
model_path <- h2o.saveModel(object=model, path=getwd(), force=TRUE)

print(model_path)
/tmp/mymodel/DeepLearning_model_R_1441838096933


# build the model
model = H2ODeepLearningEstimator(params)
model.train(params)

# save the model
model_path = h2o.save_model(model=model, path="/tmp/mymodel", force=True)

print model_path
/tmp/mymodel/DeepLearning_model_python_1441838096933



Note: When saving to HDFS, you must prepend the save directory with hdfs://. For example:

# build the model
model <- h2o.glm(model params)

# save the model to HDFS
hdfs_name_node <- "node-1"
hdfs_tmp_dir <- "/tmp/runit"
model_path <- sprintf("hdfs://%s%s", hdfs_name_node, hdfs_tmp_dir)
h2o.saveModel(model, dir=model_path, name="mymodel")

# build the model
h2o_glm = H2OGeneralizedLinearEstimator(model params)
h2o_glm.train(training params)

# save the model to HDFS
hdfs_name_node = "node-1"
hdfs_model_path = sprintf("hdfs://%s%s", hdfs_name_node, hdfs_tmp_dir)
new_model_path = h2o.save_model(h2o_glm, "hdfs://" + hdfs_name_node + "/" + hdfs_model_path)


## In Flow¶

The steps for saving and loading models in Flow are described in the Using Flow - H2O’s Web UI section. Specifically, refer to Exporting and Importing Models for information about loading models into Flow.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.18563583493232727, "perplexity": 7580.025913144933}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-09/segments/1550247494424.70/warc/CC-MAIN-20190220024254-20190220050254-00265.warc.gz"}