use of org.kie.pmml.api.models.TargetField in project drools by kiegroup.
the class PostProcessTest method executeTargets.
@Test
public void executeTargets() {
// Build model
String TARGET_NAME = "TARGET_NAME";
String FIELD_NAME = "FIELD_NAME";
TargetField targetField = new TargetField(Collections.emptyList(), null, FIELD_NAME, null, 4.34, null, null, null);
KiePMMLTarget kiePMMLTarget = KiePMMLTarget.builder(TARGET_NAME, Collections.emptyList(), targetField).build();
List<KiePMMLTarget> kiePMMLTargets = Arrays.asList(kiePMMLTarget, KiePMMLTarget.builder("NEW_TARGET", Collections.emptyList(), new TargetField(Collections.emptyList(), null, "NEW_TARGET", null, null, null, null, null)).build());
KiePMMLTestingModel model = KiePMMLTestingModel.builder("TESTINGMODEL", Collections.emptyList(), MINING_FUNCTION.REGRESSION).withKiePMMLTargets(kiePMMLTargets).build();
// Build PMML4Result
PMML4Result toModify = new PMML4Result();
toModify.setResultCode(ResultCode.FAIL.getName());
toModify.addResultVariable(FIELD_NAME, 4.33);
assertEquals(4.33, toModify.getResultVariables().get(FIELD_NAME));
ProcessingDTO processingDTO = getProcessingDTO(model, new ArrayList<>());
PostProcess.executeTargets(toModify, processingDTO);
assertEquals(4.33, toModify.getResultVariables().get(FIELD_NAME));
toModify.setResultCode(ResultCode.OK.getName());
PostProcess.executeTargets(toModify, processingDTO);
assertEquals(4.33, toModify.getResultVariables().get(FIELD_NAME));
toModify.setResultObjectName(FIELD_NAME);
PostProcess.executeTargets(toModify, processingDTO);
assertEquals(4.34, toModify.getResultVariables().get(FIELD_NAME));
}
use of org.kie.pmml.api.models.TargetField in project drools by kiegroup.
the class ModelUtils method convertToKieTargetField.
/**
* Return a <code>org.kie.pmml.api.models.TargetField</code> out of a <code>org.dmg.pmml.Target</code>
* @param toConvert
* @return
*/
public static TargetField convertToKieTargetField(final Target toConvert) {
final List<org.kie.pmml.api.models.TargetValue> targetValues = convertToKieTargetValueList(toConvert.getTargetValues());
final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
final CAST_INTEGER castInteger = toConvert.getCastInteger() != null ? CAST_INTEGER.byName(toConvert.getCastInteger().value()) : null;
final Double min = toConvert.getMin() != null ? toConvert.getMin().doubleValue() : null;
final Double max = toConvert.getMax() != null ? toConvert.getMax().doubleValue() : null;
final Double rescaleConstant = toConvert.getRescaleConstant() != null ? toConvert.getRescaleConstant().doubleValue() : null;
final Double rescaleFactor = toConvert.getRescaleFactor() != null ? toConvert.getRescaleFactor().doubleValue() : null;
return new TargetField(targetValues, opType, toConvert.getField().getValue(), castInteger, min, max, rescaleConstant, rescaleFactor);
}
use of org.kie.pmml.api.models.TargetField in project drools by kiegroup.
the class KiePMMLTargetTest method applyMax.
@Test
public void applyMax() {
TargetField targetField = new TargetField(Collections.emptyList(), null, "string", null, null, null, null, null);
KiePMMLTarget kiePMMLTarget = getBuilder(targetField).build();
assertEquals(4.33, kiePMMLTarget.applyMax(4.33), 0.0);
targetField = new TargetField(Collections.emptyList(), null, "string", null, null, 4.34, null, null);
kiePMMLTarget = getBuilder(targetField).build();
assertEquals(4.33, kiePMMLTarget.applyMax(4.33), 0.0);
assertEquals(4.34, kiePMMLTarget.applyMax(4.35), 0.0);
}
use of org.kie.pmml.api.models.TargetField in project drools by kiegroup.
the class KiePMMLTargetTest method modifyPrediction.
@Test
public void modifyPrediction() {
Object object = "STRING";
TargetField targetField = new TargetField(Collections.emptyList(), null, "string", null, null, null, null, null);
KiePMMLTarget kiePMMLTarget = getBuilder(targetField).build();
assertEquals(object, kiePMMLTarget.modifyPrediction(object));
object = 4.33;
assertEquals(object, kiePMMLTarget.modifyPrediction(object));
targetField = new TargetField(Collections.emptyList(), null, "string", null, 4.34, null, null, null);
kiePMMLTarget = getBuilder(targetField).build();
object = "STRING";
assertEquals(object, kiePMMLTarget.modifyPrediction(object));
object = 4.33;
assertEquals(4.34, kiePMMLTarget.modifyPrediction(object));
}
use of org.kie.pmml.api.models.TargetField in project drools by kiegroup.
the class KiePMMLTargetTest method applyRescaleConstant.
@Test
public void applyRescaleConstant() {
TargetField targetField = new TargetField(Collections.emptyList(), null, "string", null, null, null, null, null);
KiePMMLTarget kiePMMLTarget = getBuilder(targetField).build();
assertEquals(6.0, kiePMMLTarget.applyRescaleConstant(6.0), 0.0);
targetField = new TargetField(Collections.emptyList(), null, "string", null, null, null, 2.0, null);
kiePMMLTarget = getBuilder(targetField).build();
assertEquals(8.0, kiePMMLTarget.applyRescaleConstant(6.0), 0.0);
}
Aggregations