use of org.kie.pmml.commons.model.KiePMMLMiningField in project drools by kiegroup.
the class PreProcessTest method manageMissingValuesNotReturnInvalid.
@Test
public void manageMissingValuesNotReturnInvalid() {
List<MISSING_VALUE_TREATMENT_METHOD> missingValueTreatmentMethods = Arrays.stream(MISSING_VALUE_TREATMENT_METHOD.values()).filter(treatmentMethod -> !treatmentMethod.equals(MISSING_VALUE_TREATMENT_METHOD.RETURN_INVALID)).collect(Collectors.toList());
final String fieldName = "FIELD";
missingValueTreatmentMethods.forEach(missingValueTreatmentMethod -> {
KiePMMLMiningField miningField = KiePMMLMiningField.builder(fieldName, null).withMissingValueTreatmentMethod(missingValueTreatmentMethod).build();
PMMLRequestData pmmlRequestData = new PMMLRequestData();
PreProcess.manageMissingValues(miningField, pmmlRequestData);
assertTrue(pmmlRequestData.getRequestParams().isEmpty());
String missingValueReplacement = "REPLACEMENT";
miningField = KiePMMLMiningField.builder(fieldName, null).withDataType(DATA_TYPE.STRING).withMissingValueTreatmentMethod(missingValueTreatmentMethod).withMissingValueReplacement(missingValueReplacement).build();
pmmlRequestData = new PMMLRequestData();
PreProcess.manageMissingValues(miningField, pmmlRequestData);
assertEquals(1, pmmlRequestData.getRequestParams().size());
assertTrue(pmmlRequestData.getMappedRequestParams().containsKey(fieldName));
ParameterInfo parameterInfo = pmmlRequestData.getMappedRequestParams().get(fieldName);
assertEquals(missingValueReplacement, parameterInfo.getValue());
assertEquals(String.class, parameterInfo.getType());
});
}
use of org.kie.pmml.commons.model.KiePMMLMiningField in project drools by kiegroup.
the class PreProcess method preProcess.
/**
* Method to create a <code>ProcessingDTO</code> with <b>fix</b> values from the given <code>KiePMMLModel</code>
* @param model
* @param context
* @return
*/
public static ProcessingDTO preProcess(final KiePMMLModel model, final PMMLContext context) {
final List<KiePMMLMiningField> notTargetMiningFields = model.getMiningFields() != null ? model.getKiePMMLMiningFields().stream().filter(miningField -> !miningField.isTarget()).collect(Collectors.toList()) : Collections.emptyList();
final PMMLRequestData requestData = context.getRequestData();
convertInputData(notTargetMiningFields, requestData);
verifyFixInvalidValues(notTargetMiningFields, requestData);
verifyAddMissingValues(notTargetMiningFields, requestData);
final ProcessingDTO toReturn = createProcessingDTO(model, requestData.getMappedRequestParams());
executeTransformations(toReturn, requestData);
return toReturn;
}
use of org.kie.pmml.commons.model.KiePMMLMiningField in project drools by kiegroup.
the class KiePMMLMiningFieldInstanceFactoryTest method getKiePMMLMiningField.
@Test
public void getKiePMMLMiningField() {
DataField dataField = getRandomDataField();
MiningField toConvert = getRandomMiningField(dataField);
KiePMMLMiningField toVerify = KiePMMLMiningFieldInstanceFactory.getKiePMMLMiningField(toConvert, dataField);
commonVerifyKiePMMLMiningField(toVerify, toConvert, dataField);
}
use of org.kie.pmml.commons.model.KiePMMLMiningField in project drools by kiegroup.
the class PreProcessTest method verifyFixInvalidValuesInvalidAsMissing.
@Test
public void verifyFixInvalidValuesInvalidAsMissing() {
KiePMMLMiningField miningField0 = KiePMMLMiningField.builder("FIELD-0", null).withDataType(DATA_TYPE.STRING).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_MISSING).withAllowedValues(Arrays.asList("123", "124", "125")).build();
KiePMMLMiningField miningField1 = KiePMMLMiningField.builder("FIELD-1", null).withDataType(DATA_TYPE.DOUBLE).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_MISSING).withAllowedValues(Arrays.asList("1.23", "12.4", "1.25")).build();
List<KiePMMLInterval> intervals = Arrays.asList(new KiePMMLInterval(0.0, 12.4, CLOSURE.CLOSED_CLOSED), new KiePMMLInterval(12.6, 14.5, CLOSURE.OPEN_CLOSED));
KiePMMLMiningField miningField2 = KiePMMLMiningField.builder("FIELD-2", null).withDataType(DATA_TYPE.DOUBLE).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_MISSING).withIntervals(intervals).build();
List<KiePMMLMiningField> miningFields = Arrays.asList(miningField0, miningField1, miningField2);
PMMLRequestData pmmlRequestData = new PMMLRequestData("123", "modelName");
pmmlRequestData.addRequestParam("FIELD-0", "122");
pmmlRequestData.addRequestParam("FIELD-1", 12.5);
pmmlRequestData.addRequestParam("FIELD-2", 14.6);
PreProcess.verifyFixInvalidValues(miningFields, pmmlRequestData);
assertTrue(pmmlRequestData.getRequestParams().isEmpty());
}
use of org.kie.pmml.commons.model.KiePMMLMiningField in project drools by kiegroup.
the class PreProcessTest method verifyFixInvalidValuesInvalidAsValueWithoutReplacement.
@Test(expected = KiePMMLException.class)
public void verifyFixInvalidValuesInvalidAsValueWithoutReplacement() {
KiePMMLMiningField miningField0 = KiePMMLMiningField.builder("FIELD-0", null).withDataType(DATA_TYPE.STRING).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_VALUE).withAllowedValues(Arrays.asList("123", "124", "125")).build();
KiePMMLMiningField miningField1 = KiePMMLMiningField.builder("FIELD-1", null).withDataType(DATA_TYPE.DOUBLE).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_VALUE).withAllowedValues(Arrays.asList("1.23", "12.4", "1.25")).build();
List<KiePMMLInterval> intervals = Arrays.asList(new KiePMMLInterval(0.0, 12.4, CLOSURE.CLOSED_CLOSED), new KiePMMLInterval(12.6, 14.5, CLOSURE.OPEN_CLOSED));
KiePMMLMiningField miningField2 = KiePMMLMiningField.builder("FIELD-2", null).withDataType(DATA_TYPE.DOUBLE).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_VALUE).withIntervals(intervals).build();
List<KiePMMLMiningField> miningFields = Arrays.asList(miningField0, miningField1, miningField2);
PMMLRequestData pmmlRequestData = new PMMLRequestData("123", "modelName");
pmmlRequestData.addRequestParam("FIELD-0", "122");
pmmlRequestData.addRequestParam("FIELD-1", 12.5);
pmmlRequestData.addRequestParam("FIELD-2", 14.6);
PreProcess.verifyFixInvalidValues(miningFields, pmmlRequestData);
}
Aggregations