Skip to main content

MOJO capabilities

H2O-3 Secure

H2O-3 Secure provides the supported, production-grade path for scoring and inspecting models with the MOJO API. Contact enterprise@h2o.ai.

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

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.

  • hex.genmodel.tools

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("isolation_forest.zip");
double [] predictions = new double[]{Double.NaN, Double.NaN};
mojoModel.score0(new double[]{100, 100}, predictions);
System.out.println(Arrays.toString(predictions));

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 MOJO models contain the following attributes:

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

// Correspond to model._model_json['output']['scoring_history']
attributes.getScoringHistory();

// 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.
attributes.getTrainingMetrics();

// 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.
attributes.getValidationMetrics();

// 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.
attributes.getCrossValidationMetrics();

// Correspond to model._model_json['output']['cross_validation_metrics_summary']
attributes.getCrossValidationMetricsSummary();

// Model parameters setting when the model was built
attributes.getModelParameters();

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

ModelAttributes subclasses​

Subclasses of ModelAttributes are used to handle model-specific attributes (for example, variable importance).

// Must call with metadata flag set to True
MojoModel model = MojoModel.load("GBM_model.zip", true);
SharedTreeModelAttributes attributes = ((SharedTreeModelAttributes) model._modelAttributes);
String[] variables = attributes.getVariableImportances()._variables;
double[] importances = attributes.getVariableImportances()._importances;
System.out.print(variables[0] + ": ");
System.out.println(importances[0]);

Feedback