Search in sources :

Example 1 with DecisionTreePredictBatchOp

use of com.alibaba.alink.operator.batch.classification.DecisionTreePredictBatchOp in project Alink by alibaba.

the class Chap09 method c_5.

static void c_5() throws Exception {
    BatchOperator train_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TRAIN_FILE);
    BatchOperator test_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TEST_FILE);
    for (TreeType treeType : new TreeType[] { TreeType.GINI, TreeType.INFOGAIN, TreeType.INFOGAINRATIO }) {
        BatchOperator<?> model = train_data.link(new DecisionTreeTrainBatchOp().setTreeType(treeType).setFeatureCols(FEATURE_COL_NAMES).setCategoricalCols(FEATURE_COL_NAMES).setLabelCol(LABEL_COL_NAME).lazyPrintModelInfo("< " + treeType.toString() + " >").lazyCollectModelInfo(new Consumer<DecisionTreeModelInfo>() {

            @Override
            public void accept(DecisionTreeModelInfo decisionTreeModelInfo) {
                try {
                    decisionTreeModelInfo.saveTreeAsImage(DATA_DIR + "tree_" + treeType.toString() + ".jpg", true);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }));
        DecisionTreePredictBatchOp predictor = new DecisionTreePredictBatchOp().setPredictionCol(PREDICTION_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME);
        predictor.linkFrom(model, test_data);
        predictor.link(new EvalBinaryClassBatchOp().setPositiveLabelValueString("p").setLabelCol(LABEL_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME).lazyPrintMetrics("< " + treeType.toString() + " >"));
    }
    BatchOperator.execute();
}
Also used : TreeType(com.alibaba.alink.params.shared.tree.HasIndividualTreeType.TreeType) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) Consumer(java.util.function.Consumer) DecisionTreeModelInfo(com.alibaba.alink.operator.common.tree.TreeModelInfo.DecisionTreeModelInfo) IOException(java.io.IOException) DecisionTreePredictBatchOp(com.alibaba.alink.operator.batch.classification.DecisionTreePredictBatchOp) BatchOperator(com.alibaba.alink.operator.batch.BatchOperator) DecisionTreeTrainBatchOp(com.alibaba.alink.operator.batch.classification.DecisionTreeTrainBatchOp) EvalBinaryClassBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalBinaryClassBatchOp)

Aggregations

BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)1 DecisionTreePredictBatchOp (com.alibaba.alink.operator.batch.classification.DecisionTreePredictBatchOp)1 DecisionTreeTrainBatchOp (com.alibaba.alink.operator.batch.classification.DecisionTreeTrainBatchOp)1 EvalBinaryClassBatchOp (com.alibaba.alink.operator.batch.evaluation.EvalBinaryClassBatchOp)1 AkSourceBatchOp (com.alibaba.alink.operator.batch.source.AkSourceBatchOp)1 DecisionTreeModelInfo (com.alibaba.alink.operator.common.tree.TreeModelInfo.DecisionTreeModelInfo)1 TreeType (com.alibaba.alink.params.shared.tree.HasIndividualTreeType.TreeType)1 IOException (java.io.IOException)1 Consumer (java.util.function.Consumer)1