MOJO Capabilities

This section describes the basics of working with the MOJO model in H2O-3.

About H2O Generated MOJO Models

For information about quick starting and building MOJOs, look here. For information on how to use the h2o-genmodel, look here.

The h2o-genmodel API contains:

  • hex.genmodel.algos

All algorithms that support the MOJO model can be found here. These models can be loaded and directly used to score or perform other model-specific actions. For further documentation of the methods, refer to the javadoc of the GenModel class.

  • hex.genmodel.easy.EasyPredictModelWrapper

This wrapper gives MOJO models an easy, readable interface for scoring and other model-specific actions.

  • hex.genmodel.easy.prediction

This gives the predictions that can be called from the EasyPredictModelWrapper.predict() command. For more information, refer to the javadoc of the prediction classes.

  • hex.genmodel.easy.CategoricalEncoder

Classes from this interface can be used to preprocess raw data values to the proper categorical values expected by the model.

  • hex.genmodel.attributes.metrics

This package provides the different metrics for model-specific needs.


These java command line tools can be used for various types of applications: printing decision trees, reading a CSV file and making predictions, reading a CSV file and munging it, etc.

Predicting Values with MOJO

MojoModel mojoModel = MojoModel.load("");
double [] predictions = new double[]{Double.NaN, Double.NaN};
mojoModel.score0(new double[]{100, 100}, predictions);
IsolationForestMojoModel mojoModel = (IsolationForestMojoModel) MojoModel.load("");

EasyPredictModelWrapper.Config config = new EasyPredictModelWrapper.Config()
EasyPredictModelWrapper model = new EasyPredictModelWrapper(config);

RowData row = new RowData();
row.put("x", "100");
row.put("y", "100");

AnomalyDetectionPrediction p = (AnomalyDetectionPrediction) model.predict(row);
System.out.println("[" + p.normalizedScore + ", " + p.score + "]");

Metadata Contained in the MOJO Model

All h2o-3 models contains some metadata. To access this, type the following respective commands:

Type the <model variable name> within the console.
# All metadata

# Useful metadata

# Description of available keys
// Must call with metadata flag set to True
MojoModel model = MojoModel.load("", true);
ModelAttributes attributes = model._modelAttributes;

All MOJO models contain the following attributes:

// Correspond to model._model_json['output']['model_summary'] (Number of trees, Size of model,..)

// Correspond to model._model_json['output']['scoring_history']

// Correspond to model._model_json['output']['training_metrics']
// but only some values are available (MSE, RMSE,...)
// and for example confusion Matrix and other is omitted.

// Correspond to model._model_json['output']['validation_metrics']
// but only some values are available (MSE, RMSE,...)
// and for example confusion Matrix and other is omitted.

// Correspond to model._model_json['output']['cross_validation_metrics']
// but only some values are available (MSE, RMSE,...)
// and for example confusion Matrix and other is omitted.

// Correspond to model._model_json['output']['cross_validation_metrics_summary']

// Model parameters setting when the model was built

Accessing Model Trees

The following example shows a way to access the number of trees from the model:

# Build and train your model
model <- h2o.randomForest(...)

# Print the number of trees
print(paste("Number of Trees: ", model@allparameters$ntrees))
# Build and train your model
model = H2ORandomForestEstimator(...)

# Print the number of trees
print("Number of Trees: {}".format(model._model_json["output"]["model_summary"]["number_of_trees"]))
// Load the MOJO model
MojoModel model = MojoModel.load("", true);

// Retrieve the model attributes
ModelAttributes attributes = model._modelAttributes;
System.out.print(attributes.getModelSummary().getColHeaders()[1] + ": ");

ModelAttributes Subclasses

Subclasses of ModelAttributes are used to handle model-specific attributes (e.g. Variable Importance).

// Must call with metadata flag set to True
MojoModel model = MojoModel.load("", true);
SharedTreeModelAttributes attributes = ((SharedTreeModelAttributes) model._modelAttributes);
String[] variables = attributes.getVariableImportances()._variables;
double[] importances = attributes.getVariableImportances()._importances;
System.out.print(variables[0] + ": ");
MojoModel modelMojo = MojoModel.load("", true);
EasyPredictModelWrapper.Config config = new EasyPredictModelWrapper.Config().setModel(modelMojo);
EasyPredictModelWrapper model = new EasyPredictModelWrapper(config);
KeyValue[] importances = model.varimp();
System.out.print(importances[0].getKey() + ": ");