h2osparkling-water

H2O Mojo model from DRFModel


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?


Solution

  • 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));