Search in sources :

Example 11 with TreeModel

use of org.dmg.pmml.tree.TreeModel in project drools by kiegroup.

the class TreeModelImplementationProviderTest method getKiePMMLModel.

@Test
public void getKiePMMLModel() {
    TreeModel treeModel = (TreeModel) pmml.getModels().get(0);
    final CommonCompilationDTO<TreeModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, treeModel, new HasClassLoaderMock());
    final KiePMMLTreeModel retrieved = PROVIDER.getKiePMMLModel(compilationDTO);
    assertNotNull(retrieved);
    assertTrue(retrieved instanceof Serializable);
}
Also used : TreeModel(org.dmg.pmml.tree.TreeModel) KiePMMLTreeModel(org.kie.pmml.models.tree.model.KiePMMLTreeModel) Serializable(java.io.Serializable) KiePMMLTreeModel(org.kie.pmml.models.tree.model.KiePMMLTreeModel) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 12 with TreeModel

use of org.dmg.pmml.tree.TreeModel in project drools by kiegroup.

the class KiePMMLTreeModelFactoryTest method getKiePMMLTreeModel.

@Test
public void getKiePMMLTreeModel() {
    CommonCompilationDTO<TreeModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml1, treeModel1, new HasClassLoaderMock());
    KiePMMLTreeModel retrieved = KiePMMLTreeModelFactory.getKiePMMLTreeModel(TreeCompilationDTO.fromCompilationDTO(source));
    assertNotNull(retrieved);
    source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml2, treeModel2, new HasClassLoaderMock());
    retrieved = KiePMMLTreeModelFactory.getKiePMMLTreeModel(TreeCompilationDTO.fromCompilationDTO(source));
    assertNotNull(retrieved);
}
Also used : KiePMMLTreeModel(org.kie.pmml.models.tree.model.KiePMMLTreeModel) TreeModel(org.dmg.pmml.tree.TreeModel) KiePMMLTreeModel(org.kie.pmml.models.tree.model.KiePMMLTreeModel) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 13 with TreeModel

use of org.dmg.pmml.tree.TreeModel in project drools by kiegroup.

the class KiePMMLTreeModelFactoryTest method getKiePMMLTreeModelSourcesMap.

@Test
public void getKiePMMLTreeModelSourcesMap() {
    CommonCompilationDTO<TreeModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml1, treeModel1, new HasClassLoaderMock());
    Map<String, String> retrieved = KiePMMLTreeModelFactory.getKiePMMLTreeModelSourcesMap(TreeCompilationDTO.fromCompilationDTO(source));
    assertNotNull(retrieved);
    source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml2, treeModel2, new HasClassLoaderMock());
    retrieved = KiePMMLTreeModelFactory.getKiePMMLTreeModelSourcesMap(TreeCompilationDTO.fromCompilationDTO(source));
    assertNotNull(retrieved);
}
Also used : KiePMMLTreeModel(org.kie.pmml.models.tree.model.KiePMMLTreeModel) TreeModel(org.dmg.pmml.tree.TreeModel) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 14 with TreeModel

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

the class GBMConverter method encodeTreeModel.

private TreeModel encodeTreeModel(MiningFunction miningFunction, RGenericVector tree, RGenericVector c_splits, Schema schema) {
    Node root = encodeNode(0, True.INSTANCE, tree, c_splits, new FlagManager(), new CategoryManager(), schema);
    TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root).setSplitCharacteristic(TreeModel.SplitCharacteristic.MULTI_SPLIT);
    return treeModel;
}
Also used : TreeModel(org.dmg.pmml.tree.TreeModel) Node(org.dmg.pmml.tree.Node) BranchNode(org.dmg.pmml.tree.BranchNode) LeafNode(org.dmg.pmml.tree.LeafNode) FlagManager(org.jpmml.converter.FlagManager) CategoryManager(org.jpmml.converter.CategoryManager)

Example 15 with TreeModel

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

the class GBMConverter method encodeModel.

@Override
public MiningModel encodeModel(Schema schema) {
    RGenericVector gbm = getObject();
    RDoubleVector initF = gbm.getDoubleElement("initF");
    RGenericVector trees = gbm.getGenericElement("trees");
    RGenericVector c_splits = gbm.getGenericElement("c.splits");
    RGenericVector distribution = gbm.getGenericElement("distribution");
    RStringVector distributionName = distribution.getStringElement("name");
    Schema segmentSchema = schema.toAnonymousRegressorSchema(DataType.DOUBLE);
    List<TreeModel> treeModels = new ArrayList<>();
    for (int i = 0; i < trees.size(); i++) {
        RGenericVector tree = trees.getGenericValue(i);
        TreeModel treeModel = encodeTreeModel(MiningFunction.REGRESSION, tree, c_splits, segmentSchema);
        treeModels.add(treeModel);
    }
    MiningModel miningModel = encodeMiningModel(distributionName, treeModels, initF.asScalar(), schema);
    return miningModel;
}
Also used : TreeModel(org.dmg.pmml.tree.TreeModel) MiningModel(org.dmg.pmml.mining.MiningModel) Schema(org.jpmml.converter.Schema) 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