Search in sources :

Example 11 with DataDictionary

use of org.dmg.pmml.DataDictionary in project drools by kiegroup.

the class ModelUtilsTest method getTargetFieldName.

@Test
public void getTargetFieldName() {
    final String fieldName = "fieldName";
    MiningField.UsageType usageType = MiningField.UsageType.ACTIVE;
    MiningField miningField = getMiningField(fieldName, usageType);
    final DataField dataField = getDataField(fieldName, OpType.CATEGORICAL, DataType.STRING);
    final DataDictionary dataDictionary = new DataDictionary();
    dataDictionary.addDataFields(dataField);
    MiningSchema miningSchema = new MiningSchema();
    miningSchema.addMiningFields(miningField);
    final Model model = new RegressionModel();
    model.setMiningSchema(miningSchema);
    final List<Field<?>> fields = getFieldsFromDataDictionary(dataDictionary);
    Optional<String> retrieved = ModelUtils.getTargetFieldName(fields, model);
    assertFalse(retrieved.isPresent());
    usageType = MiningField.UsageType.PREDICTED;
    miningField = getMiningField(fieldName, usageType);
    miningSchema = new MiningSchema();
    miningSchema.addMiningFields(miningField);
    model.setMiningSchema(miningSchema);
    retrieved = ModelUtils.getTargetFieldName(fields, model);
    assertTrue(retrieved.isPresent());
    assertEquals(fieldName, retrieved.get());
}
Also used : PMMLModelTestUtils.getMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField) DataField(org.dmg.pmml.DataField) ParameterField(org.dmg.pmml.ParameterField) OutputField(org.dmg.pmml.OutputField) PMMLModelTestUtils.getDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField) Field(org.dmg.pmml.Field) DerivedField(org.dmg.pmml.DerivedField) MiningField(org.dmg.pmml.MiningField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) PMMLModelTestUtils.getRandomOutputField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomOutputField) PMMLModelTestUtils.getRandomMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField) PMMLModelTestUtils.getMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField) MiningField(org.dmg.pmml.MiningField) PMMLModelTestUtils.getRandomMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField) DataField(org.dmg.pmml.DataField) PMMLModelTestUtils.getDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) MiningSchema(org.dmg.pmml.MiningSchema) Model(org.dmg.pmml.Model) RegressionModel(org.dmg.pmml.regression.RegressionModel) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) RegressionModel(org.dmg.pmml.regression.RegressionModel) Test(org.junit.Test)

Example 12 with DataDictionary

use of org.dmg.pmml.DataDictionary in project drools by kiegroup.

the class PMMLModelTestUtils method getPMMLWithMiningRandomTestModel.

public static PMML getPMMLWithMiningRandomTestModel() {
    PMML toReturn = new PMML();
    DataDictionary dataDictionary = getRandomDataDictionary();
    toReturn.setDataDictionary(dataDictionary);
    toReturn.addModels(getRandomMiningModel(dataDictionary));
    return toReturn;
}
Also used : PMML(org.dmg.pmml.PMML) DataDictionary(org.dmg.pmml.DataDictionary)

Example 13 with DataDictionary

use of org.dmg.pmml.DataDictionary in project drools by kiegroup.

the class ModelUtilsTest method getOpTypeByMiningFieldsNotFound.

@Test(expected = KiePMMLInternalException.class)
public void getOpTypeByMiningFieldsNotFound() {
    final Model model = new RegressionModel();
    final DataDictionary dataDictionary = new DataDictionary();
    final MiningSchema miningSchema = new MiningSchema();
    IntStream.range(0, 3).forEach(i -> {
        String fieldName = "field" + i;
        final DataField dataField = getRandomDataField();
        dataField.setName(FieldName.create(fieldName));
        dataDictionary.addDataFields(dataField);
        final MiningField miningField = getRandomMiningField();
        miningField.setName(dataField.getName());
        miningSchema.addMiningFields(miningField);
    });
    model.setMiningSchema(miningSchema);
    ModelUtils.getOpType(getFieldsFromDataDictionary(dataDictionary), model, "NOT_EXISTING");
}
Also used : PMMLModelTestUtils.getMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField) MiningField(org.dmg.pmml.MiningField) PMMLModelTestUtils.getRandomMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField) MiningSchema(org.dmg.pmml.MiningSchema) DataField(org.dmg.pmml.DataField) PMMLModelTestUtils.getDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) Model(org.dmg.pmml.Model) RegressionModel(org.dmg.pmml.regression.RegressionModel) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) RegressionModel(org.dmg.pmml.regression.RegressionModel) Test(org.junit.Test)

Example 14 with DataDictionary

use of org.dmg.pmml.DataDictionary in project drools by kiegroup.

the class ModelUtilsTest method getOpTypeByDataFields.

@Test
public void getOpTypeByDataFields() {
    final Model model = new RegressionModel();
    final DataDictionary dataDictionary = new DataDictionary();
    final MiningSchema miningSchema = new MiningSchema();
    IntStream.range(0, 3).forEach(i -> {
        final DataField dataField = getRandomDataField();
        dataDictionary.addDataFields(dataField);
    });
    model.setMiningSchema(miningSchema);
    dataDictionary.getDataFields().forEach(dataField -> {
        OP_TYPE retrieved = ModelUtils.getOpType(getFieldsFromDataDictionary(dataDictionary), model, dataField.getName().getValue());
        assertNotNull(retrieved);
        OP_TYPE expected = OP_TYPE.byName(dataField.getOpType().value());
        assertEquals(expected, retrieved);
    });
}
Also used : MiningSchema(org.dmg.pmml.MiningSchema) DataField(org.dmg.pmml.DataField) PMMLModelTestUtils.getDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) Model(org.dmg.pmml.Model) RegressionModel(org.dmg.pmml.regression.RegressionModel) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) RegressionModel(org.dmg.pmml.regression.RegressionModel) Test(org.junit.Test)

Example 15 with DataDictionary

use of org.dmg.pmml.DataDictionary in project drools by kiegroup.

the class KiePMMLClassificationTableFactoryTest method getClassificationTableBuilders.

@Test
public void getClassificationTableBuilders() {
    RegressionTable regressionTableProf = getRegressionTable(3.5, "professional");
    RegressionTable regressionTableCler = getRegressionTable(27.4, "clerical");
    OutputField outputFieldCat = getOutputField("CAT-1", ResultFeature.PROBABILITY, "CatPred-1");
    OutputField outputFieldNum = getOutputField("NUM-1", ResultFeature.PROBABILITY, "NumPred-0");
    OutputField outputFieldPrev = getOutputField("PREV", ResultFeature.PREDICTED_VALUE, null);
    String targetField = "targetField";
    DataField dataField = new DataField();
    dataField.setName(FieldName.create(targetField));
    dataField.setOpType(OpType.CATEGORICAL);
    DataDictionary dataDictionary = new DataDictionary();
    dataDictionary.addDataFields(dataField);
    RegressionModel regressionModel = new RegressionModel();
    regressionModel.setNormalizationMethod(RegressionModel.NormalizationMethod.CAUCHIT);
    regressionModel.addRegressionTables(regressionTableProf, regressionTableCler);
    regressionModel.setModelName(getGeneratedClassName("RegressionModel"));
    Output output = new Output();
    output.addOutputFields(outputFieldCat, outputFieldNum, outputFieldPrev);
    regressionModel.setOutput(output);
    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, regressionModel.getRegressionTables(), regressionModel.getNormalizationMethod());
    Map<String, KiePMMLTableSourceCategory> retrieved = KiePMMLClassificationTableFactory.getClassificationTableBuilders(compilationDTO);
    assertNotNull(retrieved);
    assertEquals(3, retrieved.size());
    retrieved.values().forEach(kiePMMLTableSourceCategory -> commonValidateKiePMMLRegressionTable(kiePMMLTableSourceCategory.getSource()));
    Map<String, String> sources = retrieved.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, stringKiePMMLTableSourceCategoryEntry -> stringKiePMMLTableSourceCategoryEntry.getValue().getSource()));
    commonValidateCompilation(sources);
}
Also used : GETKIEPMML_TABLE(org.kie.pmml.models.regression.compiler.factories.KiePMMLClassificationTableFactory.GETKIEPMML_TABLE) BeforeClass(org.junit.BeforeClass) OutputField(org.dmg.pmml.OutputField) JavaParserUtils.getFromFileName(org.kie.pmml.compiler.commons.utils.JavaParserUtils.getFromFileName) KIE_PMML_CLASSIFICATION_TABLE_TEMPLATE(org.kie.pmml.models.regression.compiler.factories.KiePMMLClassificationTableFactory.KIE_PMML_CLASSIFICATION_TABLE_TEMPLATE) ResultFeature(org.dmg.pmml.ResultFeature) MiningSchema(org.dmg.pmml.MiningSchema) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) Output(org.dmg.pmml.Output) LinkedHashMap(java.util.LinkedHashMap) FieldName(org.dmg.pmml.FieldName) OpType(org.dmg.pmml.OpType) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) Map(java.util.Map) Expression(com.github.javaparser.ast.expr.Expression) Assert.fail(org.junit.Assert.fail) CompilationUnit(com.github.javaparser.ast.CompilationUnit) MiningField(org.dmg.pmml.MiningField) RegressionCompilationDTO(org.kie.pmml.models.regression.compiler.dto.RegressionCompilationDTO) SUPPORTED_NORMALIZATION_METHODS(org.kie.pmml.models.regression.compiler.factories.KiePMMLClassificationTableFactory.SUPPORTED_NORMALIZATION_METHODS) JavaParserUtils(org.kie.pmml.compiler.commons.utils.JavaParserUtils) PMML(org.dmg.pmml.PMML) RegressionModel(org.dmg.pmml.regression.RegressionModel) PACKAGE_NAME(org.kie.pmml.commons.Constants.PACKAGE_NAME) Assert.assertTrue(org.junit.Assert.assertTrue) KIE_PMML_CLASSIFICATION_TABLE_TEMPLATE_JAVA(org.kie.pmml.models.regression.compiler.factories.KiePMMLClassificationTableFactory.KIE_PMML_CLASSIFICATION_TABLE_TEMPLATE_JAVA) IOException(java.io.IOException) DataDictionary(org.dmg.pmml.DataDictionary) Test(org.junit.Test) CodegenTestUtils.commonValidateCompilation(org.kie.pmml.compiler.commons.testutils.CodegenTestUtils.commonValidateCompilation) KiePMMLClassificationTable(org.kie.pmml.models.regression.model.KiePMMLClassificationTable) RegressionTable(org.dmg.pmml.regression.RegressionTable) Collectors(java.util.stream.Collectors) KiePMMLModelUtils.getGeneratedClassName(org.kie.pmml.commons.utils.KiePMMLModelUtils.getGeneratedClassName) MethodReferenceExpr(com.github.javaparser.ast.expr.MethodReferenceExpr) FileUtils.getFileContent(org.kie.test.util.filesystem.FileUtils.getFileContent) DataField(org.dmg.pmml.DataField) KiePMMLTableSourceCategory(org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) UNSUPPORTED_NORMALIZATION_METHODS(org.kie.pmml.models.regression.compiler.factories.KiePMMLClassificationTableFactory.UNSUPPORTED_NORMALIZATION_METHODS) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) Assert.assertEquals(org.junit.Assert.assertEquals) MiningField(org.dmg.pmml.MiningField) DataDictionary(org.dmg.pmml.DataDictionary) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) RegressionTable(org.dmg.pmml.regression.RegressionTable) RegressionModel(org.dmg.pmml.regression.RegressionModel) DataField(org.dmg.pmml.DataField) MiningSchema(org.dmg.pmml.MiningSchema) Output(org.dmg.pmml.Output) KiePMMLTableSourceCategory(org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory) OutputField(org.dmg.pmml.OutputField) PMML(org.dmg.pmml.PMML) RegressionCompilationDTO(org.kie.pmml.models.regression.compiler.dto.RegressionCompilationDTO) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

DataDictionary (org.dmg.pmml.DataDictionary)48 DataField (org.dmg.pmml.DataField)41 Test (org.junit.Test)41 CommonTestingUtils.getFieldsFromDataDictionary (org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary)30 MiningSchema (org.dmg.pmml.MiningSchema)28 MiningField (org.dmg.pmml.MiningField)27 RegressionModel (org.dmg.pmml.regression.RegressionModel)27 PMMLModelTestUtils.getDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField)21 PMMLModelTestUtils.getRandomDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField)21 Model (org.dmg.pmml.Model)19 PMMLModelTestUtils.getMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField)17 PMMLModelTestUtils.getRandomMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField)17 PMML (org.dmg.pmml.PMML)12 OutputField (org.dmg.pmml.OutputField)11 Collectors (java.util.stream.Collectors)10 Assert.assertTrue (org.junit.Assert.assertTrue)10 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)10 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)10 HasClassLoaderMock (org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock)10 Arrays (java.util.Arrays)9