【问题标题】:Training H2O Stacked Ensemble Models using exported Mojo and Binary Models使用导出的 Mojo 和二进制模型训练 H2O 堆叠集成模型
【发布时间】:2019-01-23 03:52:30
【问题描述】:

我正在尝试使用 H2O Java API 构建堆叠集成模型。

为此,我训练了 2 个模型

  1. GBM 模型
  2. DRF 模型

我以 Mojo 和二进制格式导出了这些模型。对于导出模型,我使用了以下代码 sn-p:

对于 Mojo 格式导出:

        water.api.ModelsHandler modelsHandler = new ModelsHandler();
        water.api.StreamingSchema streamingSchema = modelsHandler.fetchMojo(3, modelsV3); //water.api.schemas3.ModelsV3

对于二进制格式导出:

        water.api.ModelsHandler modelsHandler = new ModelsHandler();
        modelsHandler.exportModel(3, modelExport); //water.api.schemas3.ModelExportV3

我还导出了交叉验证保留数据,因为稍后需要它来训练堆叠集成模型。

假设我导出的模型名称及其保留数据名称如下:

模型名称:StackGBMReg1 CVDataName:cv_holdout_prediction_StackGBMReg1

模型名称:StackDRFReg1 CVDataName:cv_holdout_prediction_StackDRFReg1

训练堆叠集成模型

然后我稍后将这些模型及其 CV 数据导入 H2O Server 以训练堆叠的 Ensemble 模型。这里是这个操作的代码sn-p:

导入holdout数据:

    ImportFilesV3 importFile = h2o.importFiles(workingDir + fileName); //fileName: cv_holdout_prediction_StackGBMReg1 or DRFReg1 one.

导入模型:

    ModelsHandler modelsHandler = new ModelsHandler();
    water.api.schemas3.ModelsV3 importedModel = modelsHandler.importModel(3, modelImport); //water.api.schemas3.ModelImportV3

当我尝试导入 Mojo 模型时出现以下错误。

    H2OException: Error while importing model : StackGBMReg1.zip
        at ImportAndScore.importModel(ImportAndScore.java:306)
        at ImportAndScore.main(ImportAndScore.java:61)
    Caused by: java.lang.IllegalArgumentException: Missing magic number 0x1CED at stream start
        at water.AutoBuffer.<init>(AutoBuffer.java:287)
        at hex.Model.importBinaryModel(Model.java:2380)
        at water.api.ModelsHandler.importModel(ModelsHandler.java:209)
        at ImportAndScore.importModel(ImportAndScore.java:302)
        ... 1 more

根据我在 h2o 论坛上得到的回复,不支持导入 Mojo 模型。我觉得这很奇怪。

为了克服这个问题,我导入了成功的二进制模型。然后训练了对我来说效果很好的堆叠集成模型。

我的问题是:

1. Since, mojo Model import is not working using ModelsHandler.importModel(), is there another API available or work around which can help me to import Mojo Model in H2O?
2. Can we convert, POJO or MOJO models into binary Model for import purpose?
3. As per last reply for h2o, binary models are not backward compatible. So, if I upgrade H2O later, my older trained models will not work for training new stacked ensemble models. Actually, it will fail at import step itself. 
    a. So, is there a way to use the binary models without having the backward compatibility issue?
    b. If binary models are the only way to go, then is my approach right for training stacked Ensemble models(using previously exported/saved models)?
    c. Am I likely to face any other issue with binary models in future which I dont for see now?

我主要关心的是摆脱向后兼容性问题。如果有任何方法可以解决它,那将真的有助于我的工作。因为,我使用的是 Java 代码,所以我不介意使用任何不直接公开的内部 h2o api。

请注意,我不是在谈论加载 MOJO 模型以进行评分。我知道我们可以根据此链接轻松使用 Mojo 模型进行评分: http://docs.h2o.ai/h2o/latest-stable/h2o-docs/productionizing.html

【问题讨论】:

    标签: java machine-learning h2o ensemble-learning sparkling-water


    【解决方案1】:

    在线回答您的问题:

    1.由于使用 ModelsHandler.importModel() 无法导入 mojo 模型,是否有其他可用的 API 或解决方法可以帮助我在 H2O 中导入 Mojo 模型?

    没有。 MOJO 的设计目的是便于将模型投入生产。

    2.我们可以将 POJO 或 MOJO 模型转换为二进制模型以进行导入吗? 没有。

    3.根据对 h2o 的最后回复,二进制模型不向后兼容。因此,如果我稍后升级 H2O,我的旧训练模型将无法用于训练新的堆叠集成模型。实际上,它会在导入步骤本身失败。

    是的,您只能使用与训练模型相同的 H2O 版本来加载和使用保存的二进制模型。 H2O 二进制模型在 H2O 版本之间不兼容。

    一个。那么,有没有办法在不存在向后兼容性问题的情况下使用二进制模型? 没有。

    b.如果二进制模型是唯一的方法,那么我的方法是否适合训练堆叠的 Ensemble 模型(使用以前导出/保存的模型)? 是的。

    c.将来我是否可能会面临我现在看不到的二进制模型的任何其他问题? 向后兼容性是主要问题。

    请注意,H2O.ai 未来可能会支持将 MOJO 读入 H2O-3,但目前尚无时间表。

    【讨论】:

    • 谢谢劳伦。它确实澄清了我的疑问。
    猜你喜欢
    • 2021-06-08
    • 2021-02-04
    • 1970-01-01
    • 2017-08-19
    • 2018-02-17
    • 2018-04-06
    • 1970-01-01
    • 2017-07-01
    • 2018-06-16
    相关资源
    最近更新 更多