如何在h2o中获得随机森林的树结果?

时间:2018-08-29 09:08:32

标签: random-forest h2o

我在h2o中使用随机森林。 但是我不明白返回结果中参数的含义。 这是我的原始数据。 enter image description here

我希望看到这样的结果: (我将树的数量设置为3,响应列=“播放”。)

tree1:
Wind = false: yes {no=0, yes=6}
Wind = true
|   Temperature > 77.500: no {no=2, yes=0}
|   Temperature ≤ 77.500: yes {no=1, yes=5}

tree2:
Humidity > 92.500: no {no=3, yes=0}
Humidity ≤ 92.500: yes {no=2, yes=9}

tree3:
Wind = false: yes {no=0, yes=6}
Wind = true
|   Temperature > 77.500: no {no=2, yes=0}
|   Temperature ≤ 77.500: yes {no=1, yes=5}

但是我得到了一个包含很多参数但结果的模型。 这是我的代码和得到的结果:

    DRFParametersV3 drfParams = new DRFParametersV3();
    drfParams.trainingFrame = H2oApi.stringToFrameKey("train");
    drfParams.validationFrame = H2oApi.stringToFrameKey("test");
    drfParams.ntrees=3;
    System.out.println("drfParams: " + drfParams);

    ColSpecifierV3 responseColumn = new ColSpecifierV3();
    responseColumn.columnName = ATT_LABEL_GOLF;
    drfParams.responseColumn = responseColumn;
    System.out.println("About to train DRF. . .");

    DRFV3 drfBody = h2o.train_drf(drfParams);
    System.out.println("drfParams: " + drfBody);

    JobV3 job = h2o.waitForJobCompletion(drfBody.job.key);
    System.out.println("DRF build done.");

    ModelKeyV3 modelKey = (ModelKeyV3)job.dest;
    ModelsV3 models = h2o.model(modelKey);
    System.out.println("models: " + models);
    System.out.println("models'size: " + models.models.length);

    DRFModelV3 model = (DRFModelV3)models.models[0];
    System.out.println("new DRF model: " + model);

结果“ DRFModelV3”是如此混乱。 h2o建立的“森林”在哪里? enter image description here

1 个答案:

答案 0 :(得分:1)

一种选择是下载MOJO,将其加载并在MOJO对象上使用功能_computeGraph。看看H2O github repo,以从代码中学习。

还请查看有关POJO和MOJO here

的文档

以下一些其他代码可能会有所帮助:https://github.com/h2oai/h2o-3/blob/43f8ab952a69a8bc9484bd0ffac909b6e3e820ca/h2o-algos/src/test/java/hex/XValPredictionsCheck.java#L59-L69