Skip to content

Instantly share code, notes, and snippets.

@woobe
Last active June 14, 2017 15:39
Show Gist options
  • Save woobe/a75ee98fe5cbbe3f9bd47e1acd9b007b to your computer and use it in GitHub Desktop.
Save woobe/a75ee98fe5cbbe3f9bd47e1acd9b007b to your computer and use it in GitHub Desktop.
An example of saving and loading H2O model in R
# Example: Saving and loading H2O models
# Using Iris for this example
d_train <- iris
# Initialize H2O
library(h2o)
h2o.init(nthreads = -1)
# Train a DRF model
hex_train <- as.h2o(d_train)
features <- colnames(d_train)[1:4]
target <- "Species"
DRF <- h2o.randomForest(x = features, y = target,
training_frame = hex_train,
model_id = "myDRF",
ntrees = 100)
# Save the DRF model to disk
# the model will be saved as "./folder_for_myDRF/myDRF"
h2o.saveModel(DRF, path = "folder_for_myDRF") # define your path here
# Re-load the DRF model from disk
DRF_from_disk <- h2o.loadModel(path = "./folder_for_myDRF/myDRF")
# Print the models and compare
print(DRF)
print(DRF_from_disk)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment