use of org.dmg.pmml.MiningField in project drools by kiegroup.
the class PMMLModelTestUtils method getRandomMiningField.
public static MiningField getRandomMiningField(DataField dataField) {
Random random = new Random();
MiningField toReturn = getRandomMiningField();
DataType dataType = dataField.getDataType();
toReturn.setName(dataField.getName());
toReturn.setInvalidValueReplacement(getRandomObject(dataType).toString());
toReturn.setMissingValueReplacement(getRandomObject(dataType).toString());
toReturn.setImportance(random.nextInt(10));
toReturn.setLowValue(random.nextInt(10));
toReturn.setHighValue(toReturn.getLowValue().intValue() + random.nextInt(30));
toReturn.setUsageType(getRandomUsageType());
toReturn.setOpType(getRandomOpType());
return toReturn;
}
use of org.dmg.pmml.MiningField in project drools by kiegroup.
the class ModelUtils method convertToKieMiningField.
/**
* Return a <code>org.kie.pmml.api.models.MiningField</code> out of a <code>org.dmg.pmml.MiningField</code> and
* relative <code>org.dmg.pmml.DataField</code> ones
* @param toConvert
* @param field
* @return
*/
public static org.kie.pmml.api.models.MiningField convertToKieMiningField(final MiningField toConvert, final Field<?> field) {
final String name = toConvert.getName() != null ? toConvert.getName().getValue() : null;
final FIELD_USAGE_TYPE fieldUsageType = toConvert.getUsageType() != null ? FIELD_USAGE_TYPE.byName(toConvert.getUsageType().value()) : null;
final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
final DATA_TYPE dataType = field.getDataType() != null ? DATA_TYPE.byName(field.getDataType().value()) : null;
final MISSING_VALUE_TREATMENT_METHOD missingValueTreatmentMethod = toConvert.getMissingValueTreatment() != null ? MISSING_VALUE_TREATMENT_METHOD.byName(toConvert.getMissingValueTreatment().value()) : null;
final INVALID_VALUE_TREATMENT_METHOD invalidValueTreatmentMethod = toConvert.getInvalidValueTreatment() != null ? INVALID_VALUE_TREATMENT_METHOD.byName(toConvert.getInvalidValueTreatment().value()) : null;
final String missingValueReplacement = toConvert.getMissingValueReplacement() != null ? toConvert.getMissingValueReplacement().toString() : null;
final String invalidValueReplacement = toConvert.getInvalidValueReplacement() != null ? toConvert.getInvalidValueReplacement().toString() : null;
final List<String> allowedValues = field instanceof DataField ? convertDataFieldValues(((DataField) field).getValues()) : Collections.emptyList();
final List<org.kie.pmml.api.models.Interval> intervals = field instanceof DataField ? convertDataFieldIntervals(((DataField) field).getIntervals()) : Collections.emptyList();
return new org.kie.pmml.api.models.MiningField(name, fieldUsageType, opType, dataType, missingValueTreatmentMethod, invalidValueTreatmentMethod, missingValueReplacement, invalidValueReplacement, allowedValues, intervals);
}
use of org.dmg.pmml.MiningField in project drools by kiegroup.
the class ModelUtils method getTargetFields.
/**
* Return a <code>List<KiePMMLNameOpType></code> of target fields
* Please note that only <b>predicted/target</b>
* <code>MiningField</code> are considered.
* @param fields
* @param model
* @return
*/
public static List<KiePMMLNameOpType> getTargetFields(final List<Field<?>> fields, final Model model) {
List<KiePMMLNameOpType> toReturn = new ArrayList<>();
if (model.getMiningSchema() != null && model.getMiningSchema().getMiningFields() != null) {
for (MiningField miningField : model.getMiningSchema().getMiningFields()) {
if (MiningField.UsageType.TARGET.equals(miningField.getUsageType()) || MiningField.UsageType.PREDICTED.equals(miningField.getUsageType())) {
OP_TYPE opType = getOpType(fields, model, miningField.getName().getValue());
toReturn.add(new KiePMMLNameOpType(miningField.getName().getValue(), opType));
}
}
}
return toReturn;
}
use of org.dmg.pmml.MiningField in project drools by kiegroup.
the class PMMLModelTestUtils method getRandomMiningModel.
public static MiningModel getRandomMiningModel(DataDictionary dataDictionary) {
MiningModel toReturn = new MiningModel();
List<DataField> dataFields = dataDictionary.getDataFields();
MiningSchema miningSchema = new MiningSchema();
IntStream.range(0, dataFields.size() - 1).forEach(i -> {
DataField dataField = dataFields.get(i);
MiningField miningField = new MiningField();
miningField.setName(dataField.getName());
miningField.setUsageType(MiningField.UsageType.ACTIVE);
miningSchema.addMiningFields(miningField);
});
DataField lastDataField = dataFields.get(dataFields.size() - 1);
MiningField predictedMiningField = new MiningField();
predictedMiningField.setName(lastDataField.getName());
predictedMiningField.setUsageType(MiningField.UsageType.PREDICTED);
miningSchema.addMiningFields(predictedMiningField);
Output output = new Output();
OutputField outputField = new OutputField();
outputField.setName(FieldName.create("OUTPUT_" + lastDataField.getName().getValue()));
outputField.setDataType(lastDataField.getDataType());
outputField.setOpType(getRandomOpType());
toReturn.setModelName(RandomStringUtils.random(6, true, false));
toReturn.setMiningSchema(miningSchema);
toReturn.setOutput(output);
TestModel testModel = getRandomTestModel(dataDictionary);
Segment segment = new Segment();
segment.setModel(testModel);
Segmentation segmentation = new Segmentation();
segmentation.addSegments(segment);
toReturn.setSegmentation(segmentation);
return toReturn;
}
use of org.dmg.pmml.MiningField in project drools by kiegroup.
the class PMMLModelTestUtils method getRandomTestModel.
public static TestModel getRandomTestModel(DataDictionary dataDictionary) {
TestModel toReturn = new TestModel();
List<DataField> dataFields = dataDictionary.getDataFields();
MiningSchema miningSchema = new MiningSchema();
IntStream.range(0, dataFields.size() - 1).forEach(i -> {
DataField dataField = dataFields.get(i);
MiningField miningField = new MiningField();
miningField.setName(dataField.getName());
miningField.setUsageType(MiningField.UsageType.ACTIVE);
miningSchema.addMiningFields(miningField);
});
DataField lastDataField = dataFields.get(dataFields.size() - 1);
MiningField predictedMiningField = new MiningField();
predictedMiningField.setName(lastDataField.getName());
predictedMiningField.setUsageType(MiningField.UsageType.PREDICTED);
miningSchema.addMiningFields(predictedMiningField);
Output output = new Output();
OutputField outputField = new OutputField();
outputField.setName(FieldName.create("OUTPUT_" + lastDataField.getName().getValue()));
outputField.setDataType(lastDataField.getDataType());
outputField.setOpType(getRandomOpType());
toReturn.setModelName(RandomStringUtils.random(6, true, false));
toReturn.setMiningSchema(miningSchema);
toReturn.setOutput(output);
return toReturn;
}
Aggregations