Search in sources :

Example 16 with PMMLSimplePredicate

use of org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate in project knime-core by knime.

the class ConditionExporter method setValuesFromPMMLSimplePredicate.

private void setValuesFromPMMLSimplePredicate(final SimplePredicate to, final PMMLSimplePredicate from) {
    to.setField(m_derivedFieldMapper.getDerivedFieldName(from.getSplitAttribute()));
    Operator.Enum operator;
    final PMMLOperator op = from.getOperator();
    switch(op) {
        case EQUAL:
            operator = Operator.EQUAL;
            to.setValue(from.getThreshold());
            break;
        case GREATER_OR_EQUAL:
            operator = Operator.GREATER_OR_EQUAL;
            to.setValue(from.getThreshold());
            break;
        case GREATER_THAN:
            operator = Operator.GREATER_THAN;
            to.setValue(from.getThreshold());
            break;
        case IS_MISSING:
            operator = Operator.IS_MISSING;
            break;
        case IS_NOT_MISSING:
            operator = Operator.IS_NOT_MISSING;
            break;
        case LESS_OR_EQUAL:
            operator = Operator.LESS_OR_EQUAL;
            to.setValue(from.getThreshold());
            break;
        case LESS_THAN:
            operator = Operator.LESS_THAN;
            to.setValue(from.getThreshold());
            break;
        case NOT_EQUAL:
            operator = Operator.NOT_EQUAL;
            to.setValue(from.getThreshold());
            break;
        default:
            throw new IllegalStateException("Unknown pmml operator \"" + op + "\".");
    }
    to.setOperator(operator);
}
Also used : PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator) Operator(org.dmg.pmml.SimplePredicateDocument.SimplePredicate.Operator) PMMLBooleanOperator(org.knime.base.node.mine.decisiontree2.PMMLBooleanOperator) PMMLSetOperator(org.knime.base.node.mine.decisiontree2.PMMLSetOperator) Enum(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate.BooleanOperator.Enum) PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator)

Example 17 with PMMLSimplePredicate

use of org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate in project knime-core by knime.

the class TreeNodeNumericConditionTest method testToPMML.

/**
 * This method tests the {@link TreeNodeNumericCondition#toPMMLPredicate()} method.
 *
 * @throws Exception
 */
@Test
public void testToPMML() throws Exception {
    final TreeEnsembleLearnerConfiguration config = new TreeEnsembleLearnerConfiguration(false);
    final TestDataGenerator dataGen = new TestDataGenerator(config);
    final TreeNumericColumnData col = dataGen.createNumericAttributeColumn("1,2,3,4,4,5,6,7", "testCol", 0);
    TreeNodeNumericCondition cond = new TreeNodeNumericCondition(col.getMetaData(), 3, NumericOperator.LessThanOrEqual, false);
    PMMLPredicate predicate = cond.toPMMLPredicate();
    assertThat(predicate, instanceOf(PMMLSimplePredicate.class));
    PMMLSimplePredicate simplePredicate = (PMMLSimplePredicate) predicate;
    assertEquals("Wrong attribute", col.getMetaData().getAttributeName(), simplePredicate.getSplitAttribute());
    assertEquals("Wrong operator", PMMLOperator.LESS_OR_EQUAL, simplePredicate.getOperator());
    assertEquals("Wrong threshold", Double.toString(3), simplePredicate.getThreshold());
    cond = new TreeNodeNumericCondition(col.getMetaData(), 4.5, NumericOperator.LargerThan, true);
    predicate = cond.toPMMLPredicate();
    assertThat(predicate, instanceOf(PMMLCompoundPredicate.class));
    PMMLCompoundPredicate compound = (PMMLCompoundPredicate) predicate;
    assertEquals("Wrong boolean operator in compound.", PMMLBooleanOperator.OR, compound.getBooleanOperator());
    List<PMMLPredicate> preds = compound.getPredicates();
    assertEquals("Wrong number of predicates in compound.", 2, preds.size());
    assertThat(preds.get(0), instanceOf(PMMLSimplePredicate.class));
    simplePredicate = (PMMLSimplePredicate) preds.get(0);
    assertEquals("Wrong attribute", col.getMetaData().getAttributeName(), simplePredicate.getSplitAttribute());
    assertEquals("Wrong operator", PMMLOperator.GREATER_THAN, simplePredicate.getOperator());
    assertEquals("Wrong threshold", Double.toString(4.5), simplePredicate.getThreshold());
    assertThat(preds.get(1), instanceOf(PMMLSimplePredicate.class));
    simplePredicate = (PMMLSimplePredicate) preds.get(1);
    assertEquals("Should be isMissing", PMMLOperator.IS_MISSING, simplePredicate.getOperator());
}
Also used : TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLPredicate(org.knime.base.node.mine.decisiontree2.PMMLPredicate) TreeNumericColumnData(org.knime.base.node.mine.treeensemble2.data.TreeNumericColumnData) TestDataGenerator(org.knime.base.node.mine.treeensemble2.data.TestDataGenerator) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) Test(org.junit.Test)

Example 18 with PMMLSimplePredicate

use of org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate in project knime-core by knime.

the class TreeNodeNominalBinaryCondition method toPMMLPredicate.

/**
 * {@inheritDoc}
 */
@Override
public PMMLPredicate toPMMLPredicate() {
    final PMMLSimpleSetPredicate setPredicate = new PMMLSimpleSetPredicate(getAttributeName(), m_setLogic.getPmmlSetOperator());
    setPredicate.setValues(Arrays.asList(getValues()));
    setPredicate.setArrayType(PMMLArrayType.STRING);
    if (!acceptsMissings()) {
        // if condition rejects missing values return the set predicate
        return setPredicate;
    }
    // otherwise create compound condition that allows missing values
    final PMMLCompoundPredicate compPredicate = new PMMLCompoundPredicate(PMMLBooleanOperator.OR);
    final PMMLSimplePredicate missing = new PMMLSimplePredicate();
    missing.setSplitAttribute(getAttributeName());
    missing.setOperator(PMMLOperator.IS_MISSING);
    compPredicate.addPredicate(setPredicate);
    compPredicate.addPredicate(missing);
    return compPredicate;
}
Also used : PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)

Example 19 with PMMLSimplePredicate

use of org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate in project knime-core by knime.

the class FromDecisionTreeNodeModel method setOperator.

/**
 * Sets the operator of {@code pred} based on the properties of {@code simple.}
 *
 * @param pred An xml {@link SimplePredicate}.
 * @param simple A {@link PMMLSimplePredicate}.
 */
private void setOperator(final SimplePredicate pred, final PMMLSimplePredicate simple) {
    PMMLOperator x = simple.getOperator();
    Enum e = PMMLPredicateTranslator.getOperator(x);
    if (e == null) {
        throw new UnsupportedOperationException("Unknown operator: " + x);
    }
    pred.setOperator(e);
}
Also used : Enum(org.dmg.pmml.SimplePredicateDocument.SimplePredicate.Operator.Enum) PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator)

Example 20 with PMMLSimplePredicate

use of org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate in project knime-core by knime.

the class PMMLRuleTranslator method setPredicate.

/**
 * As the predicates can be of different subclasses of {@link PMMLPredicate}, creating them adding their properties
 * to the {@code simpleRule} is done with this method.
 *
 * @param simpleRule An xml {@link SimpleRule} (recently created).
 * @param predicate A {@link PMMLPredicate} with preferably from the Rule versions of
 *            {@link PMMLRuleSimplePredicate} and {@link PMMLRuleCompoundPredicate}.
 * @since 2.12
 */
public void setPredicate(final SimpleRule simpleRule, final PMMLPredicate predicate) {
    if (predicate instanceof PMMLFalsePredicate) {
        simpleRule.addNewFalse();
    } else if (predicate instanceof PMMLTruePredicate) {
        simpleRule.addNewTrue();
    } else if (predicate instanceof PMMLSimplePredicate) {
        PMMLSimplePredicate simple = (PMMLSimplePredicate) predicate;
        SimplePredicate pred = simpleRule.addNewSimplePredicate();
        pred.setField(simple.getSplitAttribute());
        setOperator(pred, simple);
        if (simple.getThreshold() != null) {
            pred.setValue(simple.getThreshold());
        }
    } else if (predicate instanceof PMMLCompoundPredicate) {
        PMMLCompoundPredicate comp = (PMMLCompoundPredicate) predicate;
        CompoundPredicate p = simpleRule.addNewCompoundPredicate();
        setCompound(p, comp);
    } else if (predicate instanceof PMMLSimpleSetPredicate) {
        PMMLSimpleSetPredicate set = (PMMLSimpleSetPredicate) predicate;
        SimpleSetPredicate s = simpleRule.addNewSimpleSetPredicate();
        setSetPredicate(s, set);
    }
}
Also used : PMMLTruePredicate(org.knime.base.node.mine.decisiontree2.PMMLTruePredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) PMMLFalsePredicate(org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)

Aggregations

PMMLSimplePredicate (org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate)17 PMMLCompoundPredicate (org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)13 PMMLSimpleSetPredicate (org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate)12 PMMLPredicate (org.knime.base.node.mine.decisiontree2.PMMLPredicate)11 PMMLFalsePredicate (org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate)8 PMMLTruePredicate (org.knime.base.node.mine.decisiontree2.PMMLTruePredicate)8 PMMLOperator (org.knime.base.node.mine.decisiontree2.PMMLOperator)7 CompoundPredicate (org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate)5 SimplePredicate (org.dmg.pmml.SimplePredicateDocument.SimplePredicate)4 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)4 PMMLBooleanOperator (org.knime.base.node.mine.decisiontree2.PMMLBooleanOperator)4 DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)4 DecisionTreeNodeSplitPMML (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML)4 DataCell (org.knime.core.data.DataCell)4 ArrayList (java.util.ArrayList)3 Enum (org.dmg.pmml.SimplePredicateDocument.SimplePredicate.Operator.Enum)3 Test (org.junit.Test)3 DecisionTreeNodeLeaf (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeLeaf)3 LinkedHashSet (java.util.LinkedHashSet)2 Entry (java.util.Map.Entry)2