Search in sources :

Example 1 with TreeModel

use of org.dmg.pmml.tree.TreeModel in project jpmml-sparkml by jpmml.

the class GBTRegressionModelConverter method encodeModel.

@Override
public MiningModel encodeModel(Schema schema) {
    GBTRegressionModel model = getTransformer();
    List<TreeModel> treeModels = TreeModelUtil.encodeDecisionTreeEnsemble(model, schema);
    MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel())).setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.WEIGHTED_SUM, treeModels, Doubles.asList(model.treeWeights())));
    return miningModel;
}
Also used : TreeModel(org.dmg.pmml.tree.TreeModel) MiningModel(org.dmg.pmml.mining.MiningModel) GBTRegressionModel(org.apache.spark.ml.regression.GBTRegressionModel)

Example 2 with TreeModel

use of org.dmg.pmml.tree.TreeModel in project jpmml-sparkml by jpmml.

the class TreeModelCompactor method visit.

@Override
public VisitorAction visit(TreeModel treeModel) {
    TreeModel.MissingValueStrategy missingValueStrategy = treeModel.getMissingValueStrategy();
    TreeModel.NoTrueChildStrategy noTrueChildStrategy = treeModel.getNoTrueChildStrategy();
    TreeModel.SplitCharacteristic splitCharacteristic = treeModel.getSplitCharacteristic();
    if (!(TreeModel.MissingValueStrategy.NONE).equals(missingValueStrategy) || !(TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION).equals(noTrueChildStrategy) || !(TreeModel.SplitCharacteristic.BINARY_SPLIT).equals(splitCharacteristic)) {
        throw new IllegalArgumentException();
    }
    treeModel.setMissingValueStrategy(TreeModel.MissingValueStrategy.NULL_PREDICTION).setSplitCharacteristic(TreeModel.SplitCharacteristic.MULTI_SPLIT);
    MiningFunction miningFunction = treeModel.getMiningFunction();
    switch(miningFunction) {
        case REGRESSION:
            treeModel.setNoTrueChildStrategy(TreeModel.NoTrueChildStrategy.RETURN_LAST_PREDICTION);
            break;
        case CLASSIFICATION:
            break;
        default:
            throw new IllegalArgumentException();
    }
    return super.visit(treeModel);
}
Also used : TreeModel(org.dmg.pmml.tree.TreeModel) MiningFunction(org.dmg.pmml.MiningFunction)

Example 3 with TreeModel

use of org.dmg.pmml.tree.TreeModel in project pyramid by cheng-li.

the class PMMLConverter method createMiningModel.

protected static MiningModel createMiningModel(List<RegressionTree> regTrees, float base_score, Schema schema) {
    ContinuousLabel continuousLabel = (ContinuousLabel) schema.getLabel();
    Schema segmentSchema = schema.toAnonymousSchema();
    List<TreeModel> treeModels = new ArrayList<>();
    for (RegressionTree regTree : regTrees) {
        TreeModel treeModel = regTree.encodeTreeModel(segmentSchema);
        treeModels.add(treeModel);
    }
    MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(continuousLabel)).setMathContext(MathContext.FLOAT).setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.SUM, treeModels)).setTargets(ModelUtil.createRescaleTargets(null, ValueUtil.floatToDouble(base_score), continuousLabel));
    return miningModel;
}
Also used : TreeModel(org.dmg.pmml.tree.TreeModel) MiningModel(org.dmg.pmml.mining.MiningModel) RegressionTree(edu.neu.ccs.pyramid.regression.regression_tree.RegressionTree) ArrayList(java.util.ArrayList)

Example 4 with TreeModel

use of org.dmg.pmml.tree.TreeModel in project pyramid by cheng-li.

the class RegressionTree method encodeTreeModel.

// ======================PMML===========================
// this part follows the design of jpmml package
public TreeModel encodeTreeModel(Schema schema) {
    org.dmg.pmml.tree.Node root = new org.dmg.pmml.tree.Node().setPredicate(new True());
    encodeNode(root, 0, schema);
    TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), root).setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT).setMissingValueStrategy(TreeModel.MissingValueStrategy.NONE).setMathContext(MathContext.FLOAT);
    return treeModel;
}
Also used : TreeModel(org.dmg.pmml.tree.TreeModel) True(org.dmg.pmml.True)

Example 5 with TreeModel

use of org.dmg.pmml.tree.TreeModel in project pyramid by cheng-li.

the class PMMLConverter method createMiningModel.

protected static MiningModel createMiningModel(List<RegressionTree> regTrees, float base_score, Schema schema) {
    ContinuousLabel continuousLabel = (ContinuousLabel) schema.getLabel();
    Schema segmentSchema = schema.toAnonymousSchema();
    List<TreeModel> treeModels = new ArrayList<>();
    for (RegressionTree regTree : regTrees) {
        TreeModel treeModel = regTree.encodeTreeModel(segmentSchema);
        treeModels.add(treeModel);
    }
    MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(continuousLabel)).setMathContext(MathContext.FLOAT).setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.SUM, treeModels)).setTargets(ModelUtil.createRescaleTargets(null, ValueUtil.floatToDouble(base_score), continuousLabel));
    return miningModel;
}
Also used : TreeModel(org.dmg.pmml.tree.TreeModel) MiningModel(org.dmg.pmml.mining.MiningModel) RegressionTree(edu.neu.ccs.pyramid.regression.regression_tree.RegressionTree) ArrayList(java.util.ArrayList)

Aggregations

TreeModel (org.dmg.pmml.tree.TreeModel)48 MiningModel (org.dmg.pmml.mining.MiningModel)17 Node (org.dmg.pmml.tree.Node)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 BranchNode (org.dmg.pmml.tree.BranchNode)9 LeafNode (org.dmg.pmml.tree.LeafNode)9 Schema (org.jpmml.converter.Schema)9 ClassifierNode (org.dmg.pmml.tree.ClassifierNode)8 CategoricalLabel (org.jpmml.converter.CategoricalLabel)8 KiePMMLTreeModel (org.kie.pmml.models.drools.tree.model.KiePMMLTreeModel)8 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)6 HasClassLoaderMock (org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock)6 PMML (org.dmg.pmml.PMML)5 HasKnowledgeBuilderMock (org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock)5 KiePMMLTreeModel (org.kie.pmml.models.tree.model.KiePMMLTreeModel)5 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)4 Expression (com.github.javaparser.ast.expr.Expression)4 NameExpr (com.github.javaparser.ast.expr.NameExpr)4 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)4