A quick and dirty implementation of a Boot-based web service that uses H2O to make predictions using the Iris data set.
To support loading new prediction models without redeploying, the H2O models are compiled separately and stored in the database as jar files; then, they can be loaded at runtime. To illustrate this, a helper script trains both a Random Forest and a GBM using the iris data set and stores them in the database on application startup.
Have a look at the code to see how new (computed) features can be added easily.
Run gradle build
to run the script that creates the classifiers and sets the jar files inside the resources
folder.
The build file takes care of placing the generated models using custom gradle
tasks.
Run gradle bootRun
to start the embedded Tomcat server. POST
JSON requests to get predictions that can be queried using
spring data rest.
curl -X POST -H "Content-Type: application/json" -d '{
"sepalLength" : 6.9,
"sepalWidth" : 3.1,
"petalLength" : 14.9,
"petalWidth" : 1.5
}' "http://localhost:8080/predict"
curl -X GET -H "Content-Type: application/json" "http://localhost:8080/predictions"