Search in sources :

Example 21 with TestDataGenerator

use of org.knime.base.node.mine.treeensemble2.data.TestDataGenerator 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)

Aggregations

TreeEnsembleLearnerConfiguration (org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration)21 Test (org.junit.Test)19 DataMemberships (org.knime.base.node.mine.treeensemble2.data.memberships.DataMemberships)11 RootDataMemberships (org.knime.base.node.mine.treeensemble2.data.memberships.RootDataMemberships)11 TestDataGenerator (org.knime.base.node.mine.treeensemble2.data.TestDataGenerator)9 SplitCandidate (org.knime.base.node.mine.treeensemble2.learner.SplitCandidate)8 RandomData (org.apache.commons.math.random.RandomData)7 NominalBinarySplitCandidate (org.knime.base.node.mine.treeensemble2.learner.NominalBinarySplitCandidate)6 NominalMultiwaySplitCandidate (org.knime.base.node.mine.treeensemble2.learner.NominalMultiwaySplitCandidate)6 BitSet (java.util.BitSet)5 TreeNodeNominalBinaryCondition (org.knime.base.node.mine.treeensemble2.model.TreeNodeNominalBinaryCondition)5 TreeNominalColumnData (org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnData)4 DefaultDataIndexManager (org.knime.base.node.mine.treeensemble2.data.memberships.DefaultDataIndexManager)4 PMMLCompoundPredicate (org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)3 PMMLPredicate (org.knime.base.node.mine.decisiontree2.PMMLPredicate)3 PMMLSimplePredicate (org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate)3 PredictorRecord (org.knime.base.node.mine.treeensemble2.data.PredictorRecord)3 TreeNodeNominalCondition (org.knime.base.node.mine.treeensemble2.model.TreeNodeNominalCondition)3 TreeNodeNumericCondition (org.knime.base.node.mine.treeensemble2.model.TreeNodeNumericCondition)3 TreeData (org.knime.base.node.mine.treeensemble2.data.TreeData)2