Search in sources :

Example 1 with OutputField

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

the class ExternalObjectModelTest method testPMMLCustomOutput.

@Test
public void testPMMLCustomOutput() throws Exception {
    PMML pmmlDocument = null;
    String drl = null;
    if (scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_externalmodel.xls"))) {
        pmmlDocument = scorecardCompiler.getPMMLDocument();
        assertNotNull(pmmlDocument);
        PMML4Compiler.dumpModel(pmmlDocument, System.out);
        drl = scorecardCompiler.getDRL();
        assertTrue(drl != null && !drl.isEmpty());
    // System.out.println(drl);
    } else {
        fail("failed to parse scoremodel Excel.");
    }
    for (Object serializable : pmmlDocument.getAssociationModelsAndBaselineModelsAndClusteringModels()) {
        if (serializable instanceof Scorecard) {
            Scorecard scorecard = (Scorecard) serializable;
            for (Object obj : scorecard.getExtensionsAndCharacteristicsAndMiningSchemas()) {
                if (obj instanceof Output) {
                    Output output = (Output) obj;
                    final List<OutputField> outputFields = output.getOutputFields();
                    assertEquals(1, outputFields.size());
                    final OutputField outputField = outputFields.get(0);
                    assertNotNull(outputField);
                    assertEquals("totalScore", outputField.getName());
                    assertEquals("Final Score", outputField.getDisplayName());
                    assertEquals("double", outputField.getDataType().value());
                    assertEquals("predictedValue", outputField.getFeature().value());
                    final Extension extension = ScorecardPMMLUtils.getExtension(outputField.getExtensions(), PMMLExtensionNames.EXTERNAL_CLASS);
                    assertNotNull(extension);
                    assertEquals("org.drools.scorecards.example.Applicant", extension.getValue());
                    return;
                }
            }
        }
    }
    fail();
}
Also used : Extension(org.dmg.pmml.pmml_4_2.descr.Extension) Output(org.dmg.pmml.pmml_4_2.descr.Output) PMML(org.dmg.pmml.pmml_4_2.descr.PMML) OutputField(org.dmg.pmml.pmml_4_2.descr.OutputField) Scorecard(org.dmg.pmml.pmml_4_2.descr.Scorecard) Test(org.junit.Test)

Example 2 with OutputField

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

the class AbstractModel method getOutputFields.

@Override
public List<PMMLOutputField> getOutputFields() {
    List<PMMLOutputField> fields = new ArrayList<>();
    for (String key : outputFieldMap.keySet()) {
        OutputField of = outputFieldMap.get(key);
        fields.add(new PMMLOutputField(of, null, this.getModelId()));
    }
    Map<String, MiningField> includeFromMining = getFilteredMiningFieldMap(true, FIELDUSAGETYPE.PREDICTED, FIELDUSAGETYPE.TARGET);
    Map<String, PMMLDataField> dataDictionary = getOwner().getDataDictionaryMap();
    if (includeFromMining != null && !includeFromMining.isEmpty()) {
        for (String key : includeFromMining.keySet()) {
            MiningField field = includeFromMining.get(key);
            PMMLDataField df = dataDictionary.get(key);
            fields.add(new PMMLOutputField(field, df.getRawDataField(), this.getModelId()));
        }
    }
    return fields;
}
Also used : MiningField(org.kie.dmg.pmml.pmml_4_2.descr.MiningField) ArrayList(java.util.ArrayList) OutputField(org.kie.dmg.pmml.pmml_4_2.descr.OutputField)

Example 3 with OutputField

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

the class AbstractModel method initOutputFieldMap.

protected void initOutputFieldMap() {
    Output output = getOutput();
    outputFieldMap = new HashMap<>();
    if (output != null) {
        for (OutputField field : output.getOutputFields()) {
            outputFieldMap.put(field.getName(), field);
        }
    }
}
Also used : Output(org.kie.dmg.pmml.pmml_4_2.descr.Output) OutputField(org.kie.dmg.pmml.pmml_4_2.descr.OutputField)

Aggregations

OutputField (org.kie.dmg.pmml.pmml_4_2.descr.OutputField)2 ArrayList (java.util.ArrayList)1 Extension (org.dmg.pmml.pmml_4_2.descr.Extension)1 Output (org.dmg.pmml.pmml_4_2.descr.Output)1 OutputField (org.dmg.pmml.pmml_4_2.descr.OutputField)1 PMML (org.dmg.pmml.pmml_4_2.descr.PMML)1 Scorecard (org.dmg.pmml.pmml_4_2.descr.Scorecard)1 Test (org.junit.Test)1 MiningField (org.kie.dmg.pmml.pmml_4_2.descr.MiningField)1 Output (org.kie.dmg.pmml.pmml_4_2.descr.Output)1