use of org.knime.base.node.mine.treeensemble2.data.PredictorRecord in project knime-core by knime.
the class AbstractGradientBoostedTreesLearner method adaptPreviousPrediction.
/**
* Adapts the previous prediction by adding the predictions of the <b>tree</b> regulated by the respective
* coefficients in <b>coefficientMap</b>.
*
* @param previousPrediction Prediction of the previous steps
* @param tree the tree of the current iteration
* @param coefficientMap contains the coefficients for the leafs of the tree
*/
protected void adaptPreviousPrediction(final double[] previousPrediction, final TreeModelRegression tree, final Map<TreeNodeSignature, Double> coefficientMap) {
TreeData data = getData();
IDataIndexManager indexManager = getIndexManager();
for (int i = 0; i < data.getNrRows(); i++) {
PredictorRecord record = createPredictorRecord(data, indexManager, i);
previousPrediction[i] += coefficientMap.get(tree.findMatchingNode(record).getSignature());
}
}
use of org.knime.base.node.mine.treeensemble2.data.PredictorRecord in project knime-core by knime.
the class LKGradientBoostedTreesLearner method adaptPreviousFunction.
private void adaptPreviousFunction(final double[] previousFunction, final TreeModelRegression tree, final Map<TreeNodeSignature, Double> coefficientMap) {
final TreeData data = getData();
final IDataIndexManager indexManager = getIndexManager();
for (int i = 0; i < previousFunction.length; i++) {
final PredictorRecord record = createPredictorRecord(data, indexManager, i);
final TreeNodeSignature signature = tree.findMatchingNode(record).getSignature();
previousFunction[i] += coefficientMap.get(signature);
}
}
use of org.knime.base.node.mine.treeensemble2.data.PredictorRecord in project knime-core by knime.
the class TreeNodeNominalBinaryConditionTest method testTestCondition.
/**
* This method tests the
* {@link TreeNodeNominalBinaryCondition#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);
TreeNodeNominalBinaryCondition cond = new TreeNodeNominalBinaryCondition(col.getMetaData(), BigInteger.valueOf(1), true, false);
final Map<String, Object> map = Maps.newHashMap();
final String colName = col.getMetaData().getAttributeName();
map.put(colName, 0);
PredictorRecord record = new PredictorRecord(map);
assertTrue("The value A was not accepted but should have been.", 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);
assertFalse("The condition falsely accepted missing values", cond.testCondition(record));
cond = new TreeNodeNominalBinaryCondition(col.getMetaData(), BigInteger.valueOf(5), true, true);
map.clear();
map.put(colName, 0);
assertTrue("The value A was falsely rejected.", cond.testCondition(record));
map.clear();
map.put(colName, 2);
assertTrue("The value C was falsely rejected.", cond.testCondition(record));
map.clear();
map.put(colName, PredictorRecord.NULL);
assertTrue("Missing values were 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, 3);
assertFalse("The value B was falsely accepted.", cond.testCondition(record));
cond = new TreeNodeNominalBinaryCondition(col.getMetaData(), BigInteger.valueOf(5), false, true);
map.clear();
map.put(colName, 0);
assertFalse("The value A 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, PredictorRecord.NULL);
assertTrue("Missing values were falsely rejected.", cond.testCondition(record));
map.clear();
map.put(colName, 1);
assertTrue("The value B was falsely rejected.", cond.testCondition(record));
map.clear();
map.put(colName, 3);
assertTrue("The value D was falsely rejected.", cond.testCondition(record));
cond = new TreeNodeNominalBinaryCondition(col.getMetaData(), BigInteger.valueOf(5), false, false);
map.clear();
map.put(colName, 0);
assertFalse("The value A 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, PredictorRecord.NULL);
assertFalse("Missing values were falsely accepted.", cond.testCondition(record));
map.clear();
map.put(colName, 1);
assertTrue("The value B was falsely rejected.", cond.testCondition(record));
map.clear();
map.put(colName, 3);
assertTrue("The value D was falsely rejected.", cond.testCondition(record));
}
use of org.knime.base.node.mine.treeensemble2.data.PredictorRecord 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.data.PredictorRecord in project knime-core by knime.
the class AbstractTreeEnsembleModel method createDoubleVectorPredictorRecord.
private PredictorRecord createDoubleVectorPredictorRecord(final DataRow filterRow) {
assert filterRow.getNumCells() == 1 : "Expected one cell as double vector data";
final DataCell c = filterRow.getCell(0);
if (c.isMissing()) {
return null;
}
final DoubleVectorValue dv = (DoubleVectorValue) c;
final int length = dv.getLength();
if (length != getMetaData().getNrAttributes()) {
throw new IllegalArgumentException("The double-vector in " + filterRow.getKey().getString() + " has the wrong length. (" + length + " instead of " + getMetaData().getNrAttributes() + ")");
}
final Map<String, Object> valueMap = new LinkedHashMap<String, Object>((int) (length / 0.75 + 1.0));
for (int i = 0; i < length; i++) {
double val = dv.getValue(i);
String attributeName = TreeNumericColumnMetaData.getAttributeNameDouble(i);
if (Double.isNaN(val)) {
// treat NaNs as missing values
valueMap.put(attributeName, PredictorRecord.NULL);
} else {
valueMap.put(attributeName, Double.valueOf(val));
}
}
return new PredictorRecord(valueMap);
}
Aggregations