use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class KiePMMLParameterFieldInstanceFactory method getKiePMMLParameterField.
static KiePMMLParameterField getKiePMMLParameterField(final ParameterField parameterField) {
DATA_TYPE dataType = parameterField.getDataType() != null ? DATA_TYPE.byName(parameterField.getDataType().value()) : null;
OP_TYPE opType = parameterField.getOpType() != null ? OP_TYPE.byName(parameterField.getOpType().value()) : null;
return KiePMMLParameterField.builder(parameterField.getName().getValue(), Collections.emptyList()).withDataType(dataType).withOpType(opType).withDisplayName(parameterField.getDisplayName()).build();
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class PreProcessTest method convertInputDataConvertibles.
@Test
public void convertInputDataConvertibles() {
List<KiePMMLMiningField> miningFields = IntStream.range(0, 3).mapToObj(i -> {
DATA_TYPE dataType = DATA_TYPE.values()[i];
return KiePMMLMiningField.builder("FIELD-" + i, null).withDataType(dataType).build();
}).collect(Collectors.toList());
PMMLRequestData pmmlRequestData = new PMMLRequestData("123", "modelName");
pmmlRequestData.addRequestParam("FIELD-0", 123);
pmmlRequestData.addRequestParam("FIELD-1", "123");
pmmlRequestData.addRequestParam("FIELD-2", "1.23");
Map<String, ParameterInfo> mappedRequestParams = pmmlRequestData.getMappedRequestParams();
assertEquals(123, mappedRequestParams.get("FIELD-0").getValue());
assertEquals("123", mappedRequestParams.get("FIELD-1").getValue());
assertEquals("1.23", mappedRequestParams.get("FIELD-2").getValue());
PreProcess.convertInputData(miningFields, pmmlRequestData);
assertEquals("123", mappedRequestParams.get("FIELD-0").getValue());
assertEquals(123, mappedRequestParams.get("FIELD-1").getValue());
assertEquals(1.23f, mappedRequestParams.get("FIELD-2").getValue());
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class PreProcessTest method verifyAddMissingValuesMissingReturnInvalid.
@Test(expected = KiePMMLException.class)
public void verifyAddMissingValuesMissingReturnInvalid() {
List<KiePMMLMiningField> miningFields = IntStream.range(0, 3).mapToObj(i -> {
DATA_TYPE dataType = DATA_TYPE.values()[i];
return KiePMMLMiningField.builder("FIELD-" + i, null).withDataType(dataType).withMissingValueTreatmentMethod(MISSING_VALUE_TREATMENT_METHOD.RETURN_INVALID).build();
}).collect(Collectors.toList());
PMMLRequestData pmmlRequestData = new PMMLRequestData("123", "modelName");
PreProcess.verifyAddMissingValues(miningFields, pmmlRequestData);
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class PostProcess method updateTargetValueType.
/**
* Verify that the returned value has the required type as defined inside <code>DataDictionary/MiningSchema</code>
* @param model
* @param toUpdate
*/
static void updateTargetValueType(final KiePMMLModel model, final PMML4Result toUpdate) {
DATA_TYPE dataType = model.getMiningFields().stream().filter(miningField -> model.getTargetField().equals(miningField.getName())).map(MiningField::getDataType).findFirst().orElseThrow(() -> new KiePMMLException("Failed to find DATA_TYPE for " + model.getTargetField()));
Object prediction = toUpdate.getResultVariables().get(model.getTargetField());
if (prediction != null) {
Object convertedPrediction = dataType.getActualValue(prediction);
toUpdate.getResultVariables().put(model.getTargetField(), convertedPrediction);
}
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class KiePMMLScorecardModelASTFactory method getKiePMMLDroolsAST.
/**
* Returns the <code>KiePMMLDroolsAST</code> built out of the given parameters.
* It also <b>populate</b> the <b>fieldNameTypeNameMap</b> with mapping between
* original field' name and <b>original type/generated type</b> tupla
*
* @param fields
* @param model
* @param fieldTypeMap
* @param types
* @return
*/
public static KiePMMLDroolsAST getKiePMMLDroolsAST(final List<Field<?>> fields, final Scorecard model, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap, final List<KiePMMLDroolsType> types) {
logger.trace("getKiePMMLDroolsAST {} {} {}", fields, model, fieldTypeMap);
DATA_TYPE targetType = getTargetFieldType(fields, model);
List<OutputField> outputFields = model.getOutput() != null ? model.getOutput().getOutputFields() : Collections.emptyList();
KiePMMLScorecardModelCharacteristicASTFactory factory = KiePMMLScorecardModelCharacteristicASTFactory.factory(fieldTypeMap, outputFields, targetType);
if (model.isUseReasonCodes()) {
factory = factory.withReasonCodes(model.getBaselineScore(), REASONCODE_ALGORITHM.byName(model.getReasonCodeAlgorithm().value()));
}
final List<KiePMMLDroolsRule> rules = factory.declareRulesFromCharacteristics(model.getCharacteristics(), "", model.getInitialScore());
return new KiePMMLDroolsAST(types, rules);
}
Aggregations