I've trained a linear model in R and exported a POJO which I've embedded in a (Java) SpringBoot webapp. Wrapping the POJO using the EasyPredictModelWrapper and instantiating an object is well described in the tutorials:
hex.genmodel.GenModel rawModel = (hex.genmodel.GenModel) Class.forName(modelClassName).newInstance();
model = new EasyPredictModelWrapper(rawModel);
I can assemble a RowData object:
RowData row = new RowData();
row.put("feature1", this.feature1);
and obtain a prediction for that row:
BinomialModelPrediction p = model.predictBinomial(row);
I've also exported the same model as a MOJO - the deployment procedure is almost identical.
My use case is that I receive a variable-length list of objects which need scoring, so I iterate the list and construct a row for each object, pass that to the wrapper and receive the prediction. So far so good.
Now I want to use a more sophisticated model that considers all the rows simultaneously. In R it's a case of passing a dataframe to the model, rather than a row (and receiving a dataframe back).
My question is: how can I pass a dataframe to a generated model object? I've gone over the source in the h2o-3 repo, read the title of every SO post in the h2o tag and scrolled through the JIRA board until I got RSI, and the closest thing I've found is a DriverlessAI class called MojoFrame, though the example given is a transform rather than a prediction.
I'm fairly sure that the EasyPredictModelWrapper doesn't support multirow input - the source is all about the RowData class. It would be great if it does but it's not necessarily a showstopper.
I'm less sure about the underlying model implementation: the MojoFrame and FrameBuilder classes tend to imply that it's supported within DriverlessAI, which may or may not use the same MOJO. Also the H2OFrame class crops up now and then in the context of scoring from Spark/R/Python, so although that's for a native model rather than the generated Java object it gives me hope that the model format can support it, and that a possible route might be to extend the support classes.
Options I've considered but haven't tested yet:
- modify
EasyPredictModelWrapperto accept Frames (lots of effort to understand the MOJO format) - renormalise the input list into a single row (breaks the frame-based paradigm for training the model, which probably breaks the whole process)
Has anyone done multi-row / frame-based input with the generated POJO or MOJO artifacts?