use of org.dmg.pmml.DataDictionary in project drools by kiegroup.
the class ModelUtilsTest method getTargetFieldTypeWithTargetField.
@Test
public void getTargetFieldTypeWithTargetField() {
final String fieldName = "fieldName";
MiningField.UsageType usageType = MiningField.UsageType.PREDICTED;
MiningField miningField = getMiningField(fieldName, usageType);
final DataField dataField = getDataField(fieldName, OpType.CATEGORICAL, DataType.STRING);
final DataDictionary dataDictionary = new DataDictionary();
dataDictionary.addDataFields(dataField);
final MiningSchema miningSchema = new MiningSchema();
miningSchema.addMiningFields(miningField);
final Model model = new RegressionModel();
model.setMiningSchema(miningSchema);
DATA_TYPE retrieved = ModelUtils.getTargetFieldType(getFieldsFromDataDictionary(dataDictionary), model);
assertNotNull(retrieved);
assertEquals(DATA_TYPE.STRING, retrieved);
}
use of org.dmg.pmml.DataDictionary in project drools by kiegroup.
the class ModelUtilsTest method getOpTypeByMiningFields.
@Test
public void getOpTypeByMiningFields() {
final Model model = new RegressionModel();
final DataDictionary dataDictionary = new DataDictionary();
final MiningSchema miningSchema = new MiningSchema();
IntStream.range(0, 3).forEach(i -> {
final DataField dataField = getRandomDataField();
dataDictionary.addDataFields(dataField);
final MiningField miningField = getRandomMiningField();
miningField.setName(dataField.getName());
miningSchema.addMiningFields(miningField);
});
model.setMiningSchema(miningSchema);
miningSchema.getMiningFields().forEach(miningField -> {
OP_TYPE retrieved = ModelUtils.getOpType(getFieldsFromDataDictionary(dataDictionary), model, miningField.getName().getValue());
assertNotNull(retrieved);
OP_TYPE expected = OP_TYPE.byName(miningField.getOpType().value());
assertEquals(expected, retrieved);
});
}
use of org.dmg.pmml.DataDictionary in project drools by kiegroup.
the class ModelUtilsTest method getDataTypeFromDataDictionary.
@Test
public void getDataTypeFromDataDictionary() {
final DataDictionary dataDictionary = new DataDictionary();
IntStream.range(0, 3).forEach(i -> {
final DataField dataField = getRandomDataField();
dataDictionary.addDataFields(dataField);
});
dataDictionary.getDataFields().forEach(dataField -> {
DATA_TYPE retrieved = ModelUtils.getDATA_TYPE(getFieldsFromDataDictionary(dataDictionary), dataField.getName().getValue());
assertNotNull(retrieved);
DATA_TYPE expected = DATA_TYPE.byName(dataField.getDataType().value());
assertEquals(expected, retrieved);
});
}
use of org.dmg.pmml.DataDictionary in project drools by kiegroup.
the class ModelUtilsTest method getDataTypeNotFound.
@Test(expected = KiePMMLInternalException.class)
public void getDataTypeNotFound() {
final DataDictionary dataDictionary = new DataDictionary();
IntStream.range(0, 3).forEach(i -> {
String fieldName = "field" + i;
final DataField dataField = getRandomDataField();
dataField.setName(FieldName.create(fieldName));
dataDictionary.addDataFields(dataField);
});
ModelUtils.getDATA_TYPE(getFieldsFromDataDictionary(dataDictionary), "NOT_EXISTING");
}
use of org.dmg.pmml.DataDictionary in project drools by kiegroup.
the class ModelUtilsTest method getTargetFieldsWithoutTargetFieldsWithTargets.
@Test
public void getTargetFieldsWithoutTargetFieldsWithTargets() {
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 = getMiningField(dataField.getName().getValue(), MiningField.UsageType.ACTIVE);
miningSchema.addMiningFields(miningField);
final Target targetField = getTarget(dataField.getName().getValue(), null);
targets.addTargets(targetField);
});
model.setMiningSchema(miningSchema);
model.setTargets(targets);
Map<String, DATA_TYPE> retrieved = ModelUtils.getTargetFieldsTypeMap(getFieldsFromDataDictionary(dataDictionary), model);
assertNotNull(retrieved);
assertTrue(retrieved.isEmpty());
}
Aggregations