Skip to content
This repository was archived by the owner on Jun 2, 2026. It is now read-only.

mojo-resource tutorial #162

Description

@bvandorf

Hi,

In the mojo-resource tutorial, you show how to predict from a java application, during my testing I was unable to predict anything other than the default prediction shown in the tutorial even by specifically setting the testRow variable.

https://github.com/h2oai/h2o-tutorials/tree/master/tutorials/mojo-resource

`

    URL mojoURL = Main.class.getResource("irisgbm.zip");
    MojoReaderBackend reader = MojoReaderBackendFactory.createReaderBackend(mojoURL, 
    MojoReaderBackendFactory.CachingStrategy.MEMORY);
    MojoModel model = ModelMojoReader.readFrom(reader);
    EasyPredictModelWrapper modelWrapper = new EasyPredictModelWrapper(model);
    
    RowData testRow = new RowData();
    for (int i = 0; i < args.length; i++)
    {
        testRow.put("C"+i, Double.valueOf(args[i]));
    }
    if (testRow.size() == 0)
    {
        System.out.println("Add test values to testRow");
        testRow.put("C0", 5.1);
        testRow.put("C1", 3.5);
        testRow.put("C2", 1.4);
        testRow.put("C3", 0.2);
    }
    System.out.println("C0: " + testRow.get("C0"));
    System.out.println("C1: " + testRow.get("C1"));
    System.out.println("C2: " + testRow.get("C2"));
    System.out.println("C3: " + testRow.get("C3"));
    System.out.println("");
    
    MultinomialModelPrediction prediction = (MultinomialModelPrediction)modelWrapper.predict(testRow);
    
    for (int i = 0; i < prediction.classProbabilities.length; i++)
        System.out.println(modelWrapper.getResponseDomainValues()[i] + ": "+ prediction.classProbabilities[i]);
    System.out.println("Prediction: " + prediction.label);
    System.out.println("Prediction Index: " + prediction.labelIndex);

`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions