Search in sources :

Example 6 with KiePMMLTableSourceCategory

use of org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory in project drools by kiegroup.

the class KiePMMLRegressionTableFactoryTest method getRegressionTableBuilders.

@Test
public void getRegressionTableBuilders() {
    regressionTable = getRegressionTable(3.5, "professional");
    RegressionModel regressionModel = new RegressionModel();
    regressionModel.setNormalizationMethod(RegressionModel.NormalizationMethod.CAUCHIT);
    regressionModel.addRegressionTables(regressionTable);
    regressionModel.setModelName(getGeneratedClassName("RegressionModel"));
    String targetField = "targetField";
    DataField dataField = new DataField();
    dataField.setName(FieldName.create(targetField));
    dataField.setOpType(OpType.CATEGORICAL);
    DataDictionary dataDictionary = new DataDictionary();
    dataDictionary.addDataFields(dataField);
    MiningField miningField = new MiningField();
    miningField.setUsageType(MiningField.UsageType.TARGET);
    miningField.setName(dataField.getName());
    MiningSchema miningSchema = new MiningSchema();
    miningSchema.addMiningFields(miningField);
    regressionModel.setMiningSchema(miningSchema);
    PMML pmml = new PMML();
    pmml.setDataDictionary(dataDictionary);
    pmml.addModels(regressionModel);
    final CommonCompilationDTO<RegressionModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, regressionModel, new HasClassLoaderMock());
    final RegressionCompilationDTO compilationDTO = RegressionCompilationDTO.fromCompilationDTORegressionTablesAndNormalizationMethod(source, new ArrayList<>(), regressionModel.getNormalizationMethod());
    Map<String, KiePMMLTableSourceCategory> retrieved = KiePMMLRegressionTableFactory.getRegressionTableBuilders(compilationDTO);
    assertNotNull(retrieved);
    retrieved.values().forEach(kiePMMLTableSourceCategory -> commonValidateKiePMMLRegressionTable(kiePMMLTableSourceCategory.getSource()));
}
Also used : MiningField(org.dmg.pmml.MiningField) DataDictionary(org.dmg.pmml.DataDictionary) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) RegressionModel(org.dmg.pmml.regression.RegressionModel) DataField(org.dmg.pmml.DataField) MiningSchema(org.dmg.pmml.MiningSchema) KiePMMLTableSourceCategory(org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory) PMML(org.dmg.pmml.PMML) RegressionCompilationDTO(org.kie.pmml.models.regression.compiler.dto.RegressionCompilationDTO) Test(org.junit.Test)

Example 7 with KiePMMLTableSourceCategory

use of org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory in project drools by kiegroup.

the class KiePMMLClassificationTableFactory method getClassificationTableBuilders.

// Source code generation
public static Map<String, KiePMMLTableSourceCategory> getClassificationTableBuilders(final RegressionCompilationDTO compilationDTO) {
    logger.trace("getRegressionTables {}", compilationDTO.getRegressionTables());
    LinkedHashMap<String, KiePMMLTableSourceCategory> toReturn = KiePMMLRegressionTableFactory.getRegressionTableBuilders(compilationDTO);
    Map.Entry<String, String> regressionTableEntry = getClassificationTableBuilder(compilationDTO, toReturn);
    toReturn.put(regressionTableEntry.getKey(), new KiePMMLTableSourceCategory(regressionTableEntry.getValue(), ""));
    return toReturn;
}
Also used : KiePMMLTableSourceCategory(org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) CommonCodegenUtils.createPopulatedLinkedHashMap(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.createPopulatedLinkedHashMap)

Example 8 with KiePMMLTableSourceCategory

use of org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory in project drools by kiegroup.

the class KiePMMLRegressionTableFactory method getRegressionTableBuilders.

// Source code generation
public static LinkedHashMap<String, KiePMMLTableSourceCategory> getRegressionTableBuilders(final RegressionCompilationDTO compilationDTO) {
    logger.trace("getRegressionTables {}", compilationDTO.getRegressionTables());
    LinkedHashMap<String, KiePMMLTableSourceCategory> toReturn = new LinkedHashMap<>();
    for (RegressionTable regressionTable : compilationDTO.getRegressionTables()) {
        final Map.Entry<String, String> regressionTableEntry = getRegressionTableBuilder(regressionTable, compilationDTO);
        String targetCategory = regressionTable.getTargetCategory() != null ? regressionTable.getTargetCategory().toString() : "";
        toReturn.put(regressionTableEntry.getKey(), new KiePMMLTableSourceCategory(regressionTableEntry.getValue(), targetCategory));
    }
    return toReturn;
}
Also used : KiePMMLTableSourceCategory(org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory) CommonCodegenUtils.createPopulatedHashMap(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.createPopulatedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) RegressionTable(org.dmg.pmml.regression.RegressionTable) KiePMMLRegressionTable(org.kie.pmml.models.regression.model.KiePMMLRegressionTable) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with KiePMMLTableSourceCategory

use of org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory in project drools by kiegroup.

the class KiePMMLRegressionModelFactoryTest method getRegressionTablesMap.

@Test
public void getRegressionTablesMap() {
    final CompilationDTO<RegressionModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, regressionModel, new HasClassLoaderMock());
    Map<String, KiePMMLTableSourceCategory> retrieved = KiePMMLRegressionModelFactory.getRegressionTablesMap(RegressionCompilationDTO.fromCompilationDTO(compilationDTO));
    // One for classification
    int expectedSize = regressionTables.size() + 1;
    assertEquals(expectedSize, retrieved.size());
    final Collection<KiePMMLTableSourceCategory> values = retrieved.values();
    regressionTables.forEach(regressionTable -> assertTrue(values.stream().anyMatch(kiePMMLTableSourceCategory -> kiePMMLTableSourceCategory.getCategory().equals(regressionTable.getTargetCategory()))));
}
Also used : KiePMMLTableSourceCategory(org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) PMMLModelTestUtils.getRegressionModel(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRegressionModel) RegressionModel(org.dmg.pmml.regression.RegressionModel) KiePMMLRegressionModel(org.kie.pmml.models.regression.model.KiePMMLRegressionModel) Test(org.junit.Test)

Aggregations

KiePMMLTableSourceCategory (org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory)9 RegressionModel (org.dmg.pmml.regression.RegressionModel)6 RegressionTable (org.dmg.pmml.regression.RegressionTable)6 RegressionCompilationDTO (org.kie.pmml.models.regression.compiler.dto.RegressionCompilationDTO)6 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 Test (org.junit.Test)5 HasClassLoaderMock (org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock)5 DataDictionary (org.dmg.pmml.DataDictionary)4 DataField (org.dmg.pmml.DataField)4 MiningField (org.dmg.pmml.MiningField)4 MiningSchema (org.dmg.pmml.MiningSchema)4 PMML (org.dmg.pmml.PMML)4 Output (org.dmg.pmml.Output)3 OutputField (org.dmg.pmml.OutputField)3 CompilationUnit (com.github.javaparser.ast.CompilationUnit)2 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)2 IOException (java.io.IOException)2 AbstractMap (java.util.AbstractMap)2