Search in sources :

Example 11 with PMMLCompoundPredicate

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

the class TreeNodeNominalCondition method toPMMLPredicate.

/**
 * {@inheritDoc}
 */
@Override
public PMMLPredicate toPMMLPredicate() {
    final PMMLSimplePredicate simplePredicate = new PMMLSimplePredicate(getAttributeName(), PMMLOperator.EQUAL, getValue());
    if (!acceptsMissings()) {
        // return simple predicate if condition rejects missing values
        return simplePredicate;
    }
    // add compound predicate to allow for missing values
    final PMMLCompoundPredicate compPredicate = new PMMLCompoundPredicate(PMMLBooleanOperator.OR);
    compPredicate.addPredicate(simplePredicate);
    final PMMLSimplePredicate missing = new PMMLSimplePredicate();
    missing.setSplitAttribute(getAttributeName());
    missing.setOperator(PMMLOperator.IS_MISSING);
    compPredicate.addPredicate(missing);
    return compPredicate;
}
Also used : PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)

Example 12 with PMMLCompoundPredicate

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

the class TreeNodeNumericCondition method toPMMLPredicate.

/**
 * {@inheritDoc}
 */
@Override
public PMMLPredicate toPMMLPredicate() {
    PMMLCompoundPredicate compound = new PMMLCompoundPredicate(PMMLBooleanOperator.OR);
    switch(m_numericOperator) {
        case LargerThanOrMissing:
            compound.addPredicate(new PMMLSimplePredicate(getAttributeName(), PMMLOperator.GREATER_THAN, Double.toString(m_splitValue)));
            compound.addPredicate(new PMMLSimplePredicate(getAttributeName(), PMMLOperator.IS_MISSING, Double.toString(m_splitValue)));
            return compound;
        case LessThanOrEqualOrMissing:
            compound.addPredicate(new PMMLSimplePredicate(getAttributeName(), PMMLOperator.LESS_OR_EQUAL, Double.toString(m_splitValue)));
            compound.addPredicate(new PMMLSimplePredicate(getAttributeName(), PMMLOperator.IS_MISSING, Double.toString(m_splitValue)));
            return compound;
    }
    final PMMLOperator pmmlOperator = m_numericOperator.m_pmmlOperator;
    if (pmmlOperator == null) {
        throw new IllegalStateException("There is no equivalent PMMLOperator for this NumericOperator.");
    }
    final PMMLSimplePredicate simplePredicate = new PMMLSimplePredicate(getAttributeName(), pmmlOperator, Double.toString(m_splitValue));
    if (!acceptsMissings()) {
        // return simple predicate that rejects missing values
        return simplePredicate;
    }
    // create compound to allow for missing values
    compound.addPredicate(simplePredicate);
    final PMMLSimplePredicate missing = new PMMLSimplePredicate();
    missing.setSplitAttribute(getAttributeName());
    missing.setOperator(PMMLOperator.IS_MISSING);
    compound.addPredicate(missing);
    return compound;
}
Also used : PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLOperator(org.knime.base.node.mine.decisiontree2.PMMLOperator) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)

Example 13 with PMMLCompoundPredicate

use of org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate 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 14 with PMMLCompoundPredicate

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

the class AbstractTreeNodeSurrogateCondition method toPMMLPredicate.

/**
 * {@inheritDoc}
 */
@Override
public PMMLCompoundPredicate toPMMLPredicate() {
    PMMLCompoundPredicate compound = new PMMLCompoundPredicate("surrogate");
    PMMLCompoundPredicate cc = compound;
    cc.addPredicate(getFirstCondition().toPMMLPredicate());
    for (int i = 0; i < getNumSurrogates(); i++) {
        TreeNodeCondition condition = getColumnCondition(i + 1);
        PMMLCompoundPredicate nc = new PMMLCompoundPredicate("surrogate");
        nc.addPredicate(condition.toPMMLPredicate());
        cc.addPredicate(nc);
        cc = nc;
    }
    if (m_defaultResponse) {
        cc.addPredicate(new PMMLTruePredicate());
    } else {
        cc.addPredicate(new PMMLFalsePredicate());
    }
    return compound;
}
Also used : PMMLTruePredicate(org.knime.base.node.mine.decisiontree2.PMMLTruePredicate) PMMLFalsePredicate(org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)

Example 15 with PMMLCompoundPredicate

use of org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate 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)

Aggregations

PMMLCompoundPredicate (org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)17 PMMLSimplePredicate (org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate)14 PMMLPredicate (org.knime.base.node.mine.decisiontree2.PMMLPredicate)12 PMMLSimpleSetPredicate (org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate)10 PMMLFalsePredicate (org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate)9 PMMLTruePredicate (org.knime.base.node.mine.decisiontree2.PMMLTruePredicate)9 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 Test (org.junit.Test)3 Entry (java.util.Map.Entry)2 ScoreDistribution (org.dmg.pmml.ScoreDistributionDocument.ScoreDistribution)2 SimpleRule (org.dmg.pmml.SimpleRuleDocument.SimpleRule)2 PMMLOperator (org.knime.base.node.mine.decisiontree2.PMMLOperator)2 DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)2 DecisionTreeNodeSplitPMML (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML)2 TestDataGenerator (org.knime.base.node.mine.treeensemble2.data.TestDataGenerator)2 TreeEnsembleLearnerConfiguration (org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration)2 DataCell (org.knime.core.data.DataCell)2