use of org.knime.base.node.mine.treeensemble2.model.TreeNodeNominalCondition in project knime-core by knime.
the class TreeNodeNumericConditionTest method testTestCondition.
/**
* This method tests the
* {@link TreeNodeNominalCondition#testCondition(org.knime.base.node.mine.treeensemble2.data.PredictorRecord)}
* method.
*
* @throws Exception
*/
@Test
public void testTestCondition() 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);
final Map<String, Object> map = Maps.newHashMap();
final String colName = col.getMetaData().getAttributeName();
map.put(colName, 2.5);
final PredictorRecord record = new PredictorRecord(map);
assertTrue("2.5 was falsely rejected.", cond.testCondition(record));
map.clear();
map.put(colName, 3);
assertTrue("3 was falsely rejected.", cond.testCondition(record));
map.clear();
map.put(colName, 4);
assertFalse("4 was falsely accepted.", cond.testCondition(record));
map.clear();
map.put(colName, PredictorRecord.NULL);
assertFalse("Missing values were falsely accepted.", cond.testCondition(record));
cond = new TreeNodeNumericCondition(col.getMetaData(), 3, NumericOperator.LessThanOrEqual, true);
map.clear();
map.put(colName, 2.5);
assertTrue("2.5 was falsely rejected.", cond.testCondition(record));
map.clear();
map.put(colName, 3);
assertTrue("3 was falsely rejected.", cond.testCondition(record));
map.clear();
map.put(colName, 4);
assertFalse("4 was falsely accepted.", cond.testCondition(record));
map.clear();
map.put(colName, PredictorRecord.NULL);
assertTrue("Missing values were falsely rejected.", cond.testCondition(record));
cond = new TreeNodeNumericCondition(col.getMetaData(), 4, NumericOperator.LargerThan, false);
map.clear();
map.put(colName, 2.5);
assertFalse("2.5 was falsely accepted.", cond.testCondition(record));
map.clear();
map.put(colName, 3);
assertFalse("3 was falsely accepted.", cond.testCondition(record));
map.clear();
map.put(colName, 4);
assertFalse("4 was falsely accepted.", cond.testCondition(record));
map.clear();
map.put(colName, 4.01);
assertTrue("4.01 was falsely rejected.", cond.testCondition(record));
map.clear();
map.put(colName, PredictorRecord.NULL);
assertFalse("Missing values were falsely accepted.", cond.testCondition(record));
cond = new TreeNodeNumericCondition(col.getMetaData(), 4, NumericOperator.LargerThan, true);
map.clear();
map.put(colName, 2.5);
assertFalse("2.5 was falsely accepted.", cond.testCondition(record));
map.clear();
map.put(colName, 3);
assertFalse("3 was falsely accepted.", cond.testCondition(record));
map.clear();
map.put(colName, 4.01);
assertTrue("4 was falsely rejected.", cond.testCondition(record));
map.clear();
map.put(colName, PredictorRecord.NULL);
assertTrue("Missing values were falsely rejected.", cond.testCondition(record));
}
Aggregations