Skip to content

Instantly share code, notes, and snippets.

@szilard
Last active March 12, 2018 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szilard/0238a4f0455c1cfa30fbdfe8acf713a4 to your computer and use it in GitHub Desktop.
Save szilard/0238a4f0455c1cfa30fbdfe8acf713a4 to your computer and use it in GitHub Desktop.
ML Scoring (REST API) - h2o.ai
## training a model
library(h2o)
h2o.init(nthreads = -1)
dx_train <- h2o.importFile("https://s3.amazonaws.com/benchm-ml--main/train-0.1m.csv")
md_rf <- h2o.randomForest(x = 1:(ncol(dx_train)-1), y = ncol(dx_train), training_frame = dx_train,
model_id = "h2o_RF",
ntrees = 100, max_depth = 10, nbins = 100)
## exporting model for scoring
h2o.download_mojo(md_rf, path = "./h2o")
## building prediction service
# (need jetty-runner.jar ROOT.war from Steam)
java -jar jetty-runner.jar ROOT.war
curl -X POST --form mojo=@h2o_RF.zip --form jar=@h2o-genmodel.jar \
localhost:8080/makewar > h2o_RF_MOJO.war
## run prediction service
java -jar jetty-runner.jar --port 20000 h2o_RF_MOJO.war
## score via REST API
time curl "http://localhost:20000/predict?Month=c-8&DayofMonth=c-21&DayOfWeek=c-7&DepTime=1934&UniqueCarrier=AA&Origin=ATL&Dest=DFW&Distance=732"
# (fast scoring needs JVM to warm up with a few requests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment