H2O Mojo model from DRFModel

239 Views Asked by At

Having a trained DRFModel instance in scala, what's the best way of generating the corresponding MojoModel object for scoring? from the api s I've seen so far, mostly are around exporting to a file and then loading back up using the MojoModel.load(path) for instance but no direct conversion?

1

There are 1 best solutions below

0
On BEST ANSWER

The model instance currently cannot be converted to mojo instance without going through MojoWriter.

MojoWriter provides method

abstract public void writeTo(OutputStream os);

You can use it to write the mojo to a byte array (using a ByteArrayOutputStream) and then use it as a source of the mojo data:

  ByteArrayOutputStream os = new ByteArrayOutputStream();
  model.getMojo().writeTo(os);
  MojoModel mojoModel = MojoModel.load(MojoReaderBackendFactory.createReaderBackend(
          new ByteArrayInputStream(os.toByteArray()), MojoReaderBackendFactory.CachingStrategy.MEMORY));