0

I have build a StackedEnsembleModel by using autoML in my java code. But I got "water.exceptions.H2ONotFoundArgumentException: Failed to find schema for version: 3 and type: StackedEnsembleModel" exception when I try to export the model to a mojo zip file.

initH2OCloud();
try {
    registerH2OAlgorithm();
    AutoMLBuildSpec autoMLBuildSpec = new AutoMLBuildSpec();
    Frame trainFrame = importAndParseFeatureFileToH2O("/home/data/MODEL.csv");

    autoMLBuildSpec.input_spec.training_frame = trainFrame._key;
    autoMLBuildSpec.input_spec.response_column = "level";

    autoMLBuildSpec.build_models.exclude_algos = new Algo[2];
    autoMLBuildSpec.build_models.exclude_algos[0] = Algo.DeepLearning;
    autoMLBuildSpec.build_models.exclude_algos[1] = Algo.XGBoost;
    autoMLBuildSpec.build_control.keep_cross_validation_models = true;
    autoMLBuildSpec.build_control.keep_cross_validation_predictions = true;
    autoMLBuildSpec.build_control.keep_cross_validation_fold_assignment = true;
    autoMLBuildSpec.build_control.nfolds = 5;
    autoMLBuildSpec.build_control.project_name = "test.prj";
    autoMLBuildSpec.build_control.stopping_criteria.set_max_runtime_secs(300);
    AutoML aml = AutoML.makeAutoML(Key.make(), new Date(), autoMLBuildSpec);
    logger.info("Begin AutoML...");
    long beginTick = Calendar.getInstance().getTime().getTime();
    AutoML.startAutoML(autoMLBuildSpec).get();
    long usedTick = Calendar.getInstance().getTime().getTime() - beginTick;
    //save the leader model
    String modelSavePath = "/home/data/tmp";
    logger.info("best model: {}, RMSE: {}, MAE: {}, RSLE: {}。",
    aml.leader()._key.toString(),
    bigDecimalToString(new BigDecimal(Math.sqrt(aml.leader().mse())), 12),
    bigDecimalToString(new BigDecimal(Math.sqrt(aml.leader().mae())), 12),
    bigDecimalToString(new BigDecimal(Math.sqrt(aml.leader().rmsle())), 12));
    logger.info("used {} seconds", usedTick/1000L);
    logger.info("export to mojo...");
    try {
        aml.leader().getMojo().writeTo(new FileOutputStream(new File(modelSavePath + File.separator + aml.leader()._key + ".zip")));
        logger.info("export finished.");
    }
    catch (Throwable t) {
        logger.error("got exception", t);
    }
    logger.info("aml.leaderboard: ");
    logger.info(aml.leaderboard());
}
finally {
    stopH2OCloud();
}

The exception thrown when I call aml.leader().getMojo().writeTo() method. I'm using h2o 3.22.0.1. Thanks in advance.

ppzhupapa
  • 25
  • 4
  • I can see the best model is a "StackedEnsemble_AllModels" model. So I'm sure the model is created, but I cannot export it to a mojo file. Here are the exception – ppzhupapa Feb 18 '19 at 18:16
  • water.exceptions.H2ONotFoundArgumentException: Failed to find schema for version: 3 and type: StackedEnsembleModel at water.api.SchemaServer.schema(SchemaServer.java:281) at water.api.SchemaServer.schema(SchemaServer.java:251) at hex.ModelMojoWriter.writeModelDetails(ModelMojoWriter.java:92) at hex.ModelMojoWriter.writeExtraInfo(ModelMojoWriter.java:84) at hex.genmodel.AbstractMojoWriter.writeTo(AbstractMojoWriter.java:151) at hex.genmodel.AbstractMojoWriter.writeTo(AbstractMojoWriter.java:142) at – ppzhupapa Feb 18 '19 at 18:17
  • Also, I can use stackedEnsembleModel.exportBinaryModel() to export binary model. But I got same exception if I use stackedEnsembleModel.exportMojo(). – ppzhupapa Feb 19 '19 at 02:16

1 Answers1

0

Instead of aml.leader().getMojo().writeTo() try using aml.leader().exportMojo(...).

Lauren
  • 5,640
  • 1
  • 13
  • 19
  • I got same exception. Is it a wrong version issue? Or maybe I missed something in my runtime java class path? – ppzhupapa Feb 22 '19 at 06:02