Skip to content

Instantly share code, notes, and snippets.

@pschatzmann
Created November 5, 2018 19:11
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 pschatzmann/449423875ab6a51befee6ecef8f68bd7 to your computer and use it in GitHub Desktop.
Save pschatzmann/449423875ab6a51befee6ecef8f68bd7 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{"metadata":{"kernelspec":{"display_name":"Scala","language":"scala","name":"scala"},"language_info":{"codemirror_mode":"text/x-scala","file_extension":".scala","mimetype":"","name":"Scala","nbconverter_exporter":"","version":"2.11.12"}},"nbformat_minor":2,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# H2O Deployment Example with Scala\n\nThe MOJO model can be deployed to production w/o the need of any access to a running H2O or Spark Instance.\nIn this example I am using Jupyter with the [BeakerX](http://beakerx.com/) Scala kernel.\n\n## Install Jars\n\nIn theory all you need to do is to add the following dependency:\n\n <dependency>\n <groupId>ai.h2o</groupId>\n <artifactId>h2o-genmodel</artifactId>\n <version>3.10.4.2</version>\n </dependency>\n\nFurther details can be found in http://docs.h2o.ai/h2o/latest-stable/h2o-docs/productionizing.html\n\nUnfortunally this does not work in BeakerX so we need to do the following workaround:","metadata":{}},{"cell_type":"code","source":"%%bash\n\nif [ -e genmodel.jar ]\nthen\n echo \"genmodel.jar exists\"\nelse\n curl http://central.maven.org/maven2/ai/h2o/h2o-genmodel/3.22.0.1/h2o-genmodel-3.22.0.1.jar > genmodel.jar\nfi\n","metadata":{"trusted":true},"execution_count":4,"outputs":[{"name":"stdout","output_type":"stream","text":"genmodel.jar exists\n\n"}]},{"cell_type":"code","source":"%classpath add jar genmodel.jar\n%%classpath add mvn \nnet.sf.opencsv:opencsv:2.3\ncom.google.code.gson:gson:2.6.2\nai.h2o:deepwater-backend-api:1.0.4\n","metadata":{"trusted":true},"execution_count":5,"outputs":[{"output_type":"display_data","data":{"application/vnd.jupyter.widget-view+json":{"model_id":"","version_major":2,"version_minor":0},"method":"display_data"},"metadata":{}}]},{"cell_type":"markdown","source":"## Execute a Prediction\n\nWe load the Mojo model and execute the prediction with the help of the EasyPredictModelWrapper class","metadata":{}},{"cell_type":"code","source":"import hex.genmodel.easy.RowData\nimport hex.genmodel.easy.EasyPredictModelWrapper\nimport hex.genmodel.MojoModel\n\n\nvar row = new RowData()\nrow.put(\"sepal.length\", \"5.0\")\nrow.put(\"sepal.width\", \"3.4\")\nrow.put(\"petal.length\", \"1.4\")\nrow.put(\"petal.width\", \"0.2\")\n\nvar easyModel = new EasyPredictModelWrapper( MojoModel.load(\"model.mojo\"));\nvar p = easyModel.predictMultinomial(row);\n\np.label","metadata":{"trusted":true},"execution_count":6,"outputs":[{"execution_count":6,"output_type":"execute_result","data":{"text/plain":"Versicolor"},"metadata":{}}]}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment