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