Search in sources :

Example 6 with PredictorRecord

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());
    }
}
Also used : PredictorRecord(org.knime.base.node.mine.treeensemble2.data.PredictorRecord) TreeData(org.knime.base.node.mine.treeensemble2.data.TreeData) IDataIndexManager(org.knime.base.node.mine.treeensemble2.data.memberships.IDataIndexManager)

Example 7 with PredictorRecord

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);
    }
}
Also used : PredictorRecord(org.knime.base.node.mine.treeensemble2.data.PredictorRecord) TreeData(org.knime.base.node.mine.treeensemble2.data.TreeData) IDataIndexManager(org.knime.base.node.mine.treeensemble2.data.memberships.IDataIndexManager) TreeNodeSignature(org.knime.base.node.mine.treeensemble2.model.TreeNodeSignature)

Example 8 with PredictorRecord

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));
}
Also used : TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration) PredictorRecord(org.knime.base.node.mine.treeensemble2.data.PredictorRecord) TreeNominalColumnData(org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnData) TestDataGenerator(org.knime.base.node.mine.treeensemble2.data.TestDataGenerator) Test(org.junit.Test)

Example 9 with PredictorRecord

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));
}
Also used : TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration) PredictorRecord(org.knime.base.node.mine.treeensemble2.data.PredictorRecord) TreeNominalColumnData(org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnData) TestDataGenerator(org.knime.base.node.mine.treeensemble2.data.TestDataGenerator) Test(org.junit.Test)

Example 10 with PredictorRecord

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);
}
Also used : DoubleVectorValue(org.knime.core.data.vector.doublevector.DoubleVectorValue) PredictorRecord(org.knime.base.node.mine.treeensemble2.data.PredictorRecord) DataCell(org.knime.core.data.DataCell) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PredictorRecord (org.knime.base.node.mine.treeensemble2.data.PredictorRecord)16 DataCell (org.knime.core.data.DataCell)9 FilterColumnRow (org.knime.base.data.filter.column.FilterColumnRow)6 DataRow (org.knime.core.data.DataRow)6 DoubleCell (org.knime.core.data.def.DoubleCell)5 LinkedHashMap (java.util.LinkedHashMap)4 Test (org.junit.Test)3 NominalValueRepresentation (org.knime.base.node.mine.treeensemble2.data.NominalValueRepresentation)3 TestDataGenerator (org.knime.base.node.mine.treeensemble2.data.TestDataGenerator)3 TreeEnsembleModel (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModel)3 TreeEnsembleModelPortObject (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObject)3 TreeNodeRegression (org.knime.base.node.mine.treeensemble2.model.TreeNodeRegression)3 TreeEnsembleLearnerConfiguration (org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration)3 TreeEnsemblePredictorConfiguration (org.knime.base.node.mine.treeensemble2.node.predictor.TreeEnsemblePredictorConfiguration)3 IntCell (org.knime.core.data.def.IntCell)3 HashMap (java.util.HashMap)2 TreeData (org.knime.base.node.mine.treeensemble2.data.TreeData)2 TreeNominalColumnData (org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnData)2 TreeTargetNominalColumnMetaData (org.knime.base.node.mine.treeensemble2.data.TreeTargetNominalColumnMetaData)2 IDataIndexManager (org.knime.base.node.mine.treeensemble2.data.memberships.IDataIndexManager)2