Search in sources :

Example 46 with MiningField

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;
}
Also used : MiningField(org.dmg.pmml.MiningField) Random(java.util.Random) DataType(org.dmg.pmml.DataType)

Example 47 with MiningField

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);
}
Also used : MiningField(org.dmg.pmml.MiningField) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD) MISSING_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD) FIELD_USAGE_TYPE(org.kie.pmml.api.enums.FIELD_USAGE_TYPE) DataField(org.dmg.pmml.DataField) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Interval(org.dmg.pmml.Interval)

Example 48 with MiningField

use of org.dmg.pmml.MiningField in project drools by kiegroup.

the class ModelUtils method getTargetFields.

/**
 * Return a <code>List&lt;KiePMMLNameOpType&gt;</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;
}
Also used : KiePMMLNameOpType(org.kie.pmml.commons.model.tuples.KiePMMLNameOpType) MiningField(org.dmg.pmml.MiningField) ArrayList(java.util.ArrayList) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE)

Example 49 with MiningField

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;
}
Also used : MiningField(org.dmg.pmml.MiningField) MiningModel(org.dmg.pmml.mining.MiningModel) DataField(org.dmg.pmml.DataField) MiningSchema(org.dmg.pmml.MiningSchema) Segmentation(org.dmg.pmml.mining.Segmentation) Output(org.dmg.pmml.Output) OutputField(org.dmg.pmml.OutputField) TestModel(org.kie.pmml.compiler.api.mocks.TestModel) Segment(org.dmg.pmml.mining.Segment)

Example 50 with MiningField

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;
}
Also used : MiningField(org.dmg.pmml.MiningField) DataField(org.dmg.pmml.DataField) MiningSchema(org.dmg.pmml.MiningSchema) Output(org.dmg.pmml.Output) OutputField(org.dmg.pmml.OutputField) TestModel(org.kie.pmml.compiler.api.mocks.TestModel)

Aggregations

MiningField (org.dmg.pmml.MiningField)59 DataField (org.dmg.pmml.DataField)40 Test (org.junit.Test)39 MiningSchema (org.dmg.pmml.MiningSchema)33 DataDictionary (org.dmg.pmml.DataDictionary)25 RegressionModel (org.dmg.pmml.regression.RegressionModel)24 Model (org.dmg.pmml.Model)22 PMMLModelTestUtils.getRandomDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField)20 PMML (org.dmg.pmml.PMML)18 PMMLModelTestUtils.getRandomMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField)18 PMMLModelTestUtils.getMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField)17 PMMLModelTestUtils.getDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField)16 OutputField (org.dmg.pmml.OutputField)15 CommonTestingUtils.getFieldsFromDataDictionary (org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary)15 FieldName (org.dmg.pmml.FieldName)12 Target (org.dmg.pmml.Target)11 Targets (org.dmg.pmml.Targets)11 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)11 HashMap (java.util.HashMap)10 List (java.util.List)10