Search in sources :

Example 21 with True

use of org.dmg.pmml.True in project shifu by ShifuML.

the class TreeEnsemblePmmlCreator method convert.

public MiningModel convert(IndependentTreeModel treeModel) {
    MiningModel gbt = new MiningModel();
    MiningSchema miningSchema = new TreeModelMiningSchemaCreator(this.modelConfig, this.columnConfigList).build(null);
    gbt.setMiningSchema(miningSchema);
    if (treeModel.isClassification()) {
        gbt.setMiningFunction(MiningFunction.fromValue("classification"));
    } else {
        gbt.setMiningFunction(MiningFunction.fromValue("regression"));
    }
    gbt.setTargets(createTargets(this.modelConfig));
    Segmentation seg = new Segmentation();
    gbt.setSegmentation(seg);
    seg.setMultipleModelMethod(MultipleModelMethod.fromValue("weightedAverage"));
    List<Segment> list = seg.getSegments();
    int idCount = 0;
    // such case we only support treeModel is one element list
    if (treeModel.getTrees().size() != 1) {
        throw new RuntimeException("Bagging model cannot be supported in PMML generation.");
    }
    for (TreeNode tn : treeModel.getTrees().get(0)) {
        TreeNodePmmlElementCreator tnec = new TreeNodePmmlElementCreator(this.modelConfig, this.columnConfigList, treeModel);
        org.dmg.pmml.tree.Node root = tnec.convert(tn.getNode());
        TreeModelPmmlElementCreator tmec = new TreeModelPmmlElementCreator(this.modelConfig, this.columnConfigList);
        org.dmg.pmml.tree.TreeModel tm = tmec.convert(treeModel, root);
        tm.setModelName(String.valueOf(idCount));
        Segment segment = new Segment();
        if (treeModel.isGBDT()) {
            segment.setWeight(treeModel.getWeights().get(0).get(idCount) * treeModel.getTrees().size());
        } else {
            segment.setWeight(treeModel.getWeights().get(0).get(idCount));
        }
        segment.setId("Segement" + String.valueOf(idCount));
        idCount++;
        segment.setPredicate(new True());
        segment.setModel(tm);
        list.add(segment);
    }
    return gbt;
}
Also used : Segmentation(org.dmg.pmml.mining.Segmentation) True(org.dmg.pmml.True) Segment(org.dmg.pmml.mining.Segment) MiningModel(org.dmg.pmml.mining.MiningModel) MiningSchema(org.dmg.pmml.MiningSchema) TreeNode(ml.shifu.shifu.core.dtrain.dt.TreeNode)

Aggregations

True (org.dmg.pmml.True)21 Node (org.dmg.pmml.tree.Node)9 TreeModel (org.dmg.pmml.tree.TreeModel)7 SimplePredicate (org.dmg.pmml.SimplePredicate)5 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicate)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 FieldName (org.dmg.pmml.FieldName)3 Predicate (org.dmg.pmml.Predicate)3 MiningModel (org.dmg.pmml.mining.MiningModel)3 Segment (org.dmg.pmml.mining.Segment)3 Segmentation (org.dmg.pmml.mining.Segmentation)3 List (java.util.List)2 Model (org.dmg.pmml.Model)2 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 Statement (com.github.javaparser.ast.stmt.Statement)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1