Search in sources :

Example 26 with OutputField

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

the class ModelUtilsTest method convertToKieOutputField.

@Test
public void convertToKieOutputField() {
    final OutputField toConvert = getRandomOutputField();
    org.kie.pmml.api.models.OutputField retrieved = ModelUtils.convertToKieOutputField(toConvert, null);
    assertNotNull(retrieved);
    assertEquals(toConvert.getName().getValue(), retrieved.getName());
    OP_TYPE expectedOpType = OP_TYPE.byName(toConvert.getOpType().value());
    assertEquals(expectedOpType, retrieved.getOpType());
    DATA_TYPE expectedDataType = DATA_TYPE.byName(toConvert.getDataType().value());
    assertEquals(expectedDataType, retrieved.getDataType());
    assertEquals(toConvert.getTargetField().getValue(), retrieved.getTargetField());
    RESULT_FEATURE expectedResultFeature = RESULT_FEATURE.byName(toConvert.getResultFeature().value());
    assertEquals(expectedResultFeature, retrieved.getResultFeature());
    toConvert.setOpType(null);
    toConvert.setTargetField(null);
    retrieved = ModelUtils.convertToKieOutputField(toConvert, null);
    assertNull(retrieved.getOpType());
    assertNull(retrieved.getTargetField());
}
Also used : RESULT_FEATURE(org.kie.pmml.api.enums.RESULT_FEATURE) OutputField(org.dmg.pmml.OutputField) PMMLModelTestUtils.getRandomOutputField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomOutputField) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Test(org.junit.Test)

Example 27 with OutputField

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

the class PMMLModelTestUtils method getRandomMiningModel.

public static MiningModel getRandomMiningModel(DataDictionary dataDictionary) {
    MiningModel toReturn = new MiningModel();
    List<DataField> dataFields = dataDictionary.getDataFields();
    MiningSchema miningSchema = new MiningSchema();
    IntStream.range(0, dataFields.size() - 1).forEach(i -> {
        DataField dataField = dataFields.get(i);
        MiningField miningField = new MiningField();
        miningField.setName(dataField.getName());
        miningField.setUsageType(MiningField.UsageType.ACTIVE);
        miningSchema.addMiningFields(miningField);
    });
    DataField lastDataField = dataFields.get(dataFields.size() - 1);
    MiningField predictedMiningField = new MiningField();
    predictedMiningField.setName(lastDataField.getName());
    predictedMiningField.setUsageType(MiningField.UsageType.PREDICTED);
    miningSchema.addMiningFields(predictedMiningField);
    Output output = new Output();
    OutputField outputField = new OutputField();
    outputField.setName(FieldName.create("OUTPUT_" + lastDataField.getName().getValue()));
    outputField.setDataType(lastDataField.getDataType());
    outputField.setOpType(getRandomOpType());
    toReturn.setModelName(RandomStringUtils.random(6, true, false));
    toReturn.setMiningSchema(miningSchema);
    toReturn.setOutput(output);
    TestModel testModel = getRandomTestModel(dataDictionary);
    Segment segment = new Segment();
    segment.setModel(testModel);
    Segmentation segmentation = new Segmentation();
    segmentation.addSegments(segment);
    toReturn.setSegmentation(segmentation);
    return toReturn;
}
Also used : MiningField(org.dmg.pmml.MiningField) MiningModel(org.dmg.pmml.mining.MiningModel) DataField(org.dmg.pmml.DataField) MiningSchema(org.dmg.pmml.MiningSchema) Segmentation(org.dmg.pmml.mining.Segmentation) Output(org.dmg.pmml.Output) OutputField(org.dmg.pmml.OutputField) TestModel(org.kie.pmml.compiler.api.mocks.TestModel) Segment(org.dmg.pmml.mining.Segment)

Example 28 with OutputField

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

the class PMMLModelTestUtils method getRandomTestModel.

public static TestModel getRandomTestModel(DataDictionary dataDictionary) {
    TestModel toReturn = new TestModel();
    List<DataField> dataFields = dataDictionary.getDataFields();
    MiningSchema miningSchema = new MiningSchema();
    IntStream.range(0, dataFields.size() - 1).forEach(i -> {
        DataField dataField = dataFields.get(i);
        MiningField miningField = new MiningField();
        miningField.setName(dataField.getName());
        miningField.setUsageType(MiningField.UsageType.ACTIVE);
        miningSchema.addMiningFields(miningField);
    });
    DataField lastDataField = dataFields.get(dataFields.size() - 1);
    MiningField predictedMiningField = new MiningField();
    predictedMiningField.setName(lastDataField.getName());
    predictedMiningField.setUsageType(MiningField.UsageType.PREDICTED);
    miningSchema.addMiningFields(predictedMiningField);
    Output output = new Output();
    OutputField outputField = new OutputField();
    outputField.setName(FieldName.create("OUTPUT_" + lastDataField.getName().getValue()));
    outputField.setDataType(lastDataField.getDataType());
    outputField.setOpType(getRandomOpType());
    toReturn.setModelName(RandomStringUtils.random(6, true, false));
    toReturn.setMiningSchema(miningSchema);
    toReturn.setOutput(output);
    return toReturn;
}
Also used : MiningField(org.dmg.pmml.MiningField) DataField(org.dmg.pmml.DataField) MiningSchema(org.dmg.pmml.MiningSchema) Output(org.dmg.pmml.Output) OutputField(org.dmg.pmml.OutputField) TestModel(org.kie.pmml.compiler.api.mocks.TestModel)

Aggregations

OutputField (org.dmg.pmml.OutputField)28 Test (org.junit.Test)10 DataField (org.dmg.pmml.DataField)9 MiningField (org.dmg.pmml.MiningField)9 MiningSchema (org.dmg.pmml.MiningSchema)7 Output (org.dmg.pmml.Output)7 PMML (org.dmg.pmml.PMML)7 DataDictionary (org.dmg.pmml.DataDictionary)4 FieldName (org.dmg.pmml.FieldName)4 ResultFeature (org.dmg.pmml.ResultFeature)4 MiningModel (org.dmg.pmml.mining.MiningModel)4 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Collectors (java.util.stream.Collectors)3 Model (org.dmg.pmml.Model)3 OpType (org.dmg.pmml.OpType)3 RegressionModel (org.dmg.pmml.regression.RegressionModel)3