use of org.dmg.pmml.Target in project drools by kiegroup.
the class ModelUtilsTest method getTargetFieldsWithTargetFieldsWithTargetsWithOptType.
@Test
public void getTargetFieldsWithTargetFieldsWithTargetsWithOptType() {
final Model model = new RegressionModel();
final DataDictionary dataDictionary = new DataDictionary();
final MiningSchema miningSchema = new MiningSchema();
final Targets targets = new Targets();
IntStream.range(0, 3).forEach(i -> {
final String fieldName = "fieldName-" + i;
final DataField dataField = getDataField(fieldName, OpType.CATEGORICAL, DataType.STRING);
dataDictionary.addDataFields(dataField);
final MiningField miningField = getMiningField(fieldName, MiningField.UsageType.PREDICTED);
miningField.setOpType(OpType.CONTINUOUS);
miningSchema.addMiningFields(miningField);
final Target targetField = getTarget(fieldName, OpType.CATEGORICAL);
targets.addTargets(targetField);
});
model.setMiningSchema(miningSchema);
model.setTargets(targets);
List<KiePMMLNameOpType> retrieved = ModelUtils.getTargetFields(getFieldsFromDataDictionary(dataDictionary), model);
assertNotNull(retrieved);
assertEquals(miningSchema.getMiningFields().size(), retrieved.size());
retrieved.forEach(kiePMMLNameOpType -> {
Optional<Target> optionalTarget = targets.getTargets().stream().filter(fld -> kiePMMLNameOpType.getName().equals(fld.getField().getValue())).findFirst();
assertTrue(optionalTarget.isPresent());
Target target = optionalTarget.get();
OP_TYPE expected = OP_TYPE.byName(target.getOpType().value());
assertEquals(expected, kiePMMLNameOpType.getOpType());
});
}
use of org.dmg.pmml.Target in project drools by kiegroup.
the class ModelUtilsTest method getOpTypeByTargets.
@Test
public void getOpTypeByTargets() {
final Model model = new RegressionModel();
final DataDictionary dataDictionary = new DataDictionary();
final MiningSchema miningSchema = new MiningSchema();
final Targets targets = new Targets();
IntStream.range(0, 3).forEach(i -> {
final DataField dataField = getRandomDataField();
dataDictionary.addDataFields(dataField);
final MiningField miningField = getRandomMiningField();
miningField.setName(dataField.getName());
miningSchema.addMiningFields(miningField);
final Target targetField = getRandomTarget();
targetField.setField(dataField.getName());
targets.addTargets(targetField);
});
model.setMiningSchema(miningSchema);
model.setTargets(targets);
getFieldsFromDataDictionary(dataDictionary);
targets.getTargets().forEach(target -> {
OP_TYPE retrieved = ModelUtils.getOpType(getFieldsFromDataDictionary(dataDictionary), model, target.getField().getValue());
assertNotNull(retrieved);
OP_TYPE expected = OP_TYPE.byName(target.getOpType().value());
assertEquals(expected, retrieved);
});
}
use of org.dmg.pmml.Target in project drools by kiegroup.
the class PMMLModelTestUtils method getRandomTarget.
public static Target getRandomTarget() {
Random random = new Random();
Target toReturn = new Target();
toReturn.setField(FieldName.create(RandomStringUtils.random(6, true, false)));
toReturn.setOpType(getRandomOpType());
toReturn.setMax(random.nextInt(234));
toReturn.setMin(random.nextInt(23));
toReturn.setCastInteger(getRandomCastInteger());
toReturn.setRescaleConstant(random.nextInt(234));
toReturn.setRescaleFactor(random.nextInt(234));
IntStream.range(0, 3).forEach(i -> toReturn.addTargetValues(getRandomTargetValue()));
return toReturn;
}
use of org.dmg.pmml.Target in project shifu by ShifuML.
the class TreeModelPmmlElementCreator method createTargets.
protected Targets createTargets(ModelConfig modelConfig) {
Targets targets = new Targets();
Target target = new Target();
target.setOpType(OpType.CATEGORICAL);
target.setField(new FieldName(modelConfig.getTargetColumnName()));
List<TargetValue> targetValueList = new ArrayList<TargetValue>();
for (String posTagValue : modelConfig.getPosTags()) {
TargetValue pos = new TargetValue();
pos.setValue(posTagValue);
pos.setDisplayValue("Positive");
targetValueList.add(pos);
}
for (String negTagValue : modelConfig.getNegTags()) {
TargetValue neg = new TargetValue();
neg.setValue(negTagValue);
neg.setDisplayValue("Negative");
targetValueList.add(neg);
}
target.addTargetValues(targetValueList.toArray(new TargetValue[targetValueList.size()]));
targets.addTargets(target);
return targets;
}
use of org.dmg.pmml.Target in project shifu by ShifuML.
the class NNPmmlModelCreator method createMultiClassTargets.
private List<Target> createMultiClassTargets() {
List<Target> targets = new ArrayList<Target>();
for (int i = 0; i < modelConfig.getTags().size(); i++) {
String tag = modelConfig.getTags().get(i);
Target target = new Target();
target.setOpType(OpType.CONTINUOUS);
target.setField(new FieldName(modelConfig.getTargetColumnName() + "_" + i));
TargetValue targetValue = new TargetValue();
targetValue.setValue(Integer.toString(i));
targetValue.setDisplayValue(tag);
target.addTargetValues(targetValue);
targets.add(target);
}
return targets;
}
Aggregations