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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations