我正在尝试使用 H2O Java API 构建堆叠的集成模型。
为此,我训练了 2 个模型
- GBM 模型
- DRF 模型
我以 Mojo 和二进制格式导出了这些模型。对于导出模型,我使用了以下代码片段:
对于 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 模型。以下是此操作的代码片段:
要导入保留数据:
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