use of org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.
the class SurrogatesTest method createSplitCandidates.
private static SplitCandidate[] createSplitCandidates(final TreeEnsembleLearnerConfiguration config) {
double[] colBestData = TreeNumericColumnDataTest.asDataArray(COLBEST);
double[] col1Data = TreeNumericColumnDataTest.asDataArray(COL1);
double[] col2Data = TreeNumericColumnDataTest.asDataArray(COL2);
TreeOrdinaryNumericColumnData colBest = TreeNumericColumnDataTest.createNumericColumnData(config, colBestData, "colBest", 0);
colBest.getMetaData().setAttributeIndex(0);
TreeOrdinaryNumericColumnData col1 = TreeNumericColumnDataTest.createNumericColumnData(config, col1Data, "col1", 1);
col1.getMetaData().setAttributeIndex(1);
TreeOrdinaryNumericColumnData col2 = TreeNumericColumnDataTest.createNumericColumnData(config, col2Data, "col2", 2);
col2.getMetaData().setAttributeIndex(2);
NumericSplitCandidate splitBest = new NumericSplitCandidate(colBest, SPLITVAL, 0.5, createMissingBitSet(colBestData), NumericSplitCandidate.NO_MISSINGS);
NumericSplitCandidate split1 = new NumericSplitCandidate(col1, SPLITVAL, 0.25, createMissingBitSet(col1Data), NumericSplitCandidate.NO_MISSINGS);
NumericSplitCandidate split2 = new NumericSplitCandidate(col2, SPLITVAL, 0.1, createMissingBitSet(col2Data), NumericSplitCandidate.NO_MISSINGS);
return new SplitCandidate[] { splitBest, split1, split2 };
}
use of org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.
the class TreeNodeNominalConditionTest method testToPMMLPredicate.
/**
* This method tests the {@link TreeNodeNominalCondition#toPMMLPredicate()} method.
*
* @throws Exception
*/
@Test
public void testToPMMLPredicate() throws Exception {
final TreeEnsembleLearnerConfiguration config = new TreeEnsembleLearnerConfiguration(false);
final TestDataGenerator dataGen = new TestDataGenerator(config);
final TreeNominalColumnData col = dataGen.createNominalAttributeColumn("A,A,B,C,C,D", "testcol", 0);
TreeNodeNominalCondition cond = new TreeNodeNominalCondition(col.getMetaData(), 3, false);
PMMLPredicate predicate = cond.toPMMLPredicate();
assertThat(predicate, instanceOf(PMMLSimplePredicate.class));
PMMLSimplePredicate simplePredicate = (PMMLSimplePredicate) predicate;
assertEquals("Wrong operator", PMMLOperator.EQUAL, simplePredicate.getOperator());
assertEquals("Wrong split value", "D", simplePredicate.getThreshold());
cond = new TreeNodeNominalCondition(col.getMetaData(), 0, true);
predicate = cond.toPMMLPredicate();
assertThat(predicate, instanceOf(PMMLCompoundPredicate.class));
PMMLCompoundPredicate compound = (PMMLCompoundPredicate) predicate;
assertEquals("Wrong boolean operator.", PMMLBooleanOperator.OR, compound.getBooleanOperator());
List<PMMLPredicate> preds;
preds = compound.getPredicates();
assertEquals("Wrong number of predicates in compound predicate.", 2, preds.size());
assertThat(preds.get(0), instanceOf(PMMLSimplePredicate.class));
simplePredicate = (PMMLSimplePredicate) preds.get(0);
assertEquals("Wrong operator", PMMLOperator.EQUAL, simplePredicate.getOperator());
assertEquals("Wrong split value", "A", simplePredicate.getThreshold());
assertEquals("Wrong attribute.", col.getMetaData().getAttributeName(), simplePredicate.getSplitAttribute());
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.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.
the class TreeNodeNominalConditionTest 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 TreeNominalColumnData col = dataGen.createNominalAttributeColumn("A,A,B,C,C,D", "testcol", 0);
TreeNodeNominalCondition cond = new TreeNodeNominalCondition(col.getMetaData(), 3, false);
final Map<String, Object> map = Maps.newHashMap();
final String colName = col.getMetaData().getAttributeName();
map.put(colName, 0);
final PredictorRecord record = new PredictorRecord(map);
assertFalse("The value A was falsely accepted", cond.testCondition(record));
map.clear();
map.put(colName, 1);
assertFalse("The value B was falsely accepted", cond.testCondition(record));
map.clear();
map.put(colName, 2);
assertFalse("The value C was falsely accepted", cond.testCondition(record));
map.clear();
map.put(colName, 3);
assertTrue("The value D was falsely rejected", cond.testCondition(record));
map.clear();
map.put(colName, PredictorRecord.NULL);
assertFalse("Missing values were falsely accepted", cond.testCondition(record));
cond = new TreeNodeNominalCondition(col.getMetaData(), 0, true);
map.clear();
map.put(colName, 0);
assertTrue("The value A was falsely rejected", cond.testCondition(record));
map.clear();
map.put(colName, 1);
assertFalse("The value B was falsely accepted", cond.testCondition(record));
map.clear();
map.put(colName, 2);
assertFalse("The value C was falsely accepted", cond.testCondition(record));
map.clear();
map.put(colName, 3);
assertFalse("The value D was falsely accepted", cond.testCondition(record));
map.clear();
map.put(colName, PredictorRecord.NULL);
assertTrue("Missing values were falsely rejected", cond.testCondition(record));
}
use of org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.
the class TreeEnsembleClassificationLearnerNodeDialogPane method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
final DataTableSpec inSpec = specs[0];
TreeEnsembleLearnerConfiguration cfg = new TreeEnsembleLearnerConfiguration(false);
cfg.loadInDialog(settings, inSpec);
m_attributeSelectionPanel.loadSettingsFrom(inSpec, cfg);
m_treeOptionsPanel.loadSettingsFrom(inSpec, cfg);
m_ensembleOptionsPanel.loadSettings(cfg);
}
use of org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.
the class TreeEnsembleClassificationLearnerNodeModel method loadValidatedSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
TreeEnsembleLearnerConfiguration config = new TreeEnsembleLearnerConfiguration(false);
config.loadInModel(settings);
m_configuration = config;
}
Aggregations