Search in sources :

Example 1 with OPTYPE

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

the class KiePMMLUtil method getTargetDataField.

/**
 * Returns a model-specific <b>target</b> <code>DataField</code>
 * @param model
 * @return
 */
static Optional<DataField> getTargetDataField(final Model model) {
    DataType targetDataType = getTargetDataType(model.getMiningFunction(), model.getMathContext());
    OpType targetOpType = getTargetOpType(model.getMiningFunction());
    if (targetDataType == null || targetOpType == null) {
        return Optional.empty();
    }
    String cleanedName = model.getModelName().replaceAll("[^A-Za-z0-9]", "");
    String fieldName = String.format(TARGETFIELD_TEMPLATE, cleanedName);
    DataField toReturn = new DataField();
    toReturn.setName(FieldName.create(fieldName));
    toReturn.setOpType(targetOpType);
    toReturn.setDataType(targetDataType);
    return Optional.of(toReturn);
}
Also used : DataField(org.dmg.pmml.DataField) DataType(org.dmg.pmml.DataType) OpType(org.dmg.pmml.OpType)

Example 2 with OPTYPE

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

the class KiePMMLUtilTest method getTargetOpType.

@Test
public void getTargetOpType() {
    MiningFunction miningFunction = MiningFunction.REGRESSION;
    OpType retrieved = KiePMMLUtil.getTargetOpType(miningFunction);
    assertEquals(OpType.CONTINUOUS, retrieved);
    miningFunction = MiningFunction.CLASSIFICATION;
    retrieved = KiePMMLUtil.getTargetOpType(miningFunction);
    assertEquals(OpType.CATEGORICAL, retrieved);
    miningFunction = MiningFunction.CLUSTERING;
    retrieved = KiePMMLUtil.getTargetOpType(miningFunction);
    assertEquals(OpType.CATEGORICAL, retrieved);
    List<MiningFunction> notMappedMiningFunctions = Arrays.asList(MiningFunction.ASSOCIATION_RULES, MiningFunction.MIXED, MiningFunction.SEQUENCES, MiningFunction.TIME_SERIES);
    notMappedMiningFunctions.forEach(minFun -> assertNull(KiePMMLUtil.getTargetOpType(minFun)));
}
Also used : OpType(org.dmg.pmml.OpType) MiningFunction(org.dmg.pmml.MiningFunction) Test(org.junit.Test)

Example 3 with OPTYPE

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

the class RegressionCompilationDTO method isRegression.

public boolean isRegression() {
    final DataField targetDataField = getTargetDataField();
    final OpType targetOpType = targetDataField != null ? targetDataField.getOpType() : null;
    return Objects.equals(MiningFunction.REGRESSION, getMiningFunction()) && (targetDataField == null || Objects.equals(OpType.CONTINUOUS, targetOpType));
}
Also used : DataField(org.dmg.pmml.DataField) OpType(org.dmg.pmml.OpType)

Example 4 with OPTYPE

use of org.dmg.pmml.OPTYPE in project knime-core by knime.

the class PMMLStringConversionTranslator method createDerivedFields.

private DerivedField[] createDerivedFields() {
    DATATYPE.Enum dataType = PMMLDataDictionaryTranslator.getPMMLDataType(m_parseType);
    OPTYPE.Enum optype = PMMLDataDictionaryTranslator.getOptype(m_parseType);
    int num = m_includeCols.size();
    DerivedField[] derivedFields = new DerivedField[num];
    for (int i = 0; i < num; i++) {
        DerivedField df = DerivedField.Factory.newInstance();
        String name = m_includeCols.get(i);
        df.setDisplayName(name);
        /* The field name must be retrieved before creating a new derived
             * name for this derived field as the map only contains the
             * current mapping. */
        String fieldName = m_mapper.getDerivedFieldName(name);
        df.setName(m_mapper.createDerivedFieldName(name));
        df.setDataType(dataType);
        df.setOptype(optype);
        FieldRef fieldRef = df.addNewFieldRef();
        fieldRef.setField(fieldName);
        derivedFields[i] = df;
    }
    return derivedFields;
}
Also used : DATATYPE(org.dmg.pmml.DATATYPE) FieldRef(org.dmg.pmml.FieldRefDocument.FieldRef) OPTYPE(org.dmg.pmml.OPTYPE) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField)

Example 5 with OPTYPE

use of org.dmg.pmml.OPTYPE in project knime-core by knime.

the class PMMLStringConversionTranslator method createDerivedFields.

private DerivedField[] createDerivedFields() {
    DATATYPE.Enum dataType = PMMLDataDictionaryTranslator.getPMMLDataType(m_parseType);
    OPTYPE.Enum optype = PMMLDataDictionaryTranslator.getOptype(m_parseType);
    int num = m_includeCols.size();
    DerivedField[] derivedFields = new DerivedField[num];
    for (int i = 0; i < num; i++) {
        DerivedField df = DerivedField.Factory.newInstance();
        String name = m_includeCols.get(i);
        df.setDisplayName(name);
        /* The field name must be retrieved before creating a new derived
             * name for this derived field as the map only contains the
             * current mapping. */
        String fieldName = m_mapper.getDerivedFieldName(name);
        df.setName(m_mapper.createDerivedFieldName(name));
        df.setDataType(dataType);
        df.setOptype(optype);
        FieldRef fieldRef = df.addNewFieldRef();
        fieldRef.setField(fieldName);
        derivedFields[i] = df;
    }
    return derivedFields;
}
Also used : DATATYPE(org.dmg.pmml.DATATYPE) FieldRef(org.dmg.pmml.FieldRefDocument.FieldRef) OPTYPE(org.dmg.pmml.OPTYPE) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField)

Aggregations

OpType (org.dmg.pmml.OpType)8 DataField (org.dmg.pmml.DataField)5 DataType (org.dmg.pmml.DataType)4 ArrayList (java.util.ArrayList)2 DATATYPE (org.dmg.pmml.DATATYPE)2 DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)2 FieldRef (org.dmg.pmml.FieldRefDocument.FieldRef)2 OPTYPE (org.dmg.pmml.OPTYPE)2 ContinuousFeature (org.jpmml.converter.ContinuousFeature)2 ContinuousLabel (org.jpmml.converter.ContinuousLabel)2 Feature (org.jpmml.converter.Feature)2 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 DerivedField (org.dmg.pmml.DerivedField)1 Expression (org.dmg.pmml.Expression)1 FieldName (org.dmg.pmml.FieldName)1 MiningFunction (org.dmg.pmml.MiningFunction)1 CategoricalFeature (org.jpmml.converter.CategoricalFeature)1