Search in sources :

Example 1 with TreeNominalColumnMetaData

use of org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnMetaData in project knime-core by knime.

the class AbstractTreeEnsembleModel method createNominalNumericPredictorRecord.

private PredictorRecord createNominalNumericPredictorRecord(final DataRow filterRow, final DataTableSpec trainSpec) {
    final int nrCols = trainSpec.getNumColumns();
    Map<String, Object> valueMap = new LinkedHashMap<String, Object>((int) (nrCols / 0.75 + 1.0));
    for (int i = 0; i < nrCols; i++) {
        DataColumnSpec col = trainSpec.getColumnSpec(i);
        String colName = col.getName();
        DataType colType = col.getType();
        DataCell cell = filterRow.getCell(i);
        if (cell.isMissing()) {
            valueMap.put(colName, PredictorRecord.NULL);
        } else if (colType.isCompatible(NominalValue.class)) {
            TreeNominalColumnMetaData nomColMeta = (TreeNominalColumnMetaData) m_metaData.getAttributeMetaData(i);
            NominalValueRepresentation[] nomVals = nomColMeta.getValues();
            int assignedInteger = -1;
            String val = cell.toString();
            // find assignedInteger of value
            for (NominalValueRepresentation nomVal : nomVals) {
                if (nomVal.getNominalValue().equals(val)) {
                    assignedInteger = nomVal.getAssignedInteger();
                    break;
                }
            }
            // the value is not known to the model
            if (assignedInteger == -1) {
                // treat as missing value
                valueMap.put(colName, PredictorRecord.NULL);
            } else {
                valueMap.put(colName, Integer.valueOf(assignedInteger));
            }
        } else if (colType.isCompatible(DoubleValue.class)) {
            double val = ((DoubleValue) cell).getDoubleValue();
            if (Double.isNaN(val)) {
                // make sure that NaNs are treated as missing values
                // bug AP-7169
                valueMap.put(colName, PredictorRecord.NULL);
            } else {
                valueMap.put(colName, val);
            }
        } else {
            throw new IllegalStateException("Expected nominal or numeric column type for column \"" + colName + "\" but got \"" + colType + "\"");
        }
    }
    return new PredictorRecord(valueMap);
}
Also used : NominalValue(org.knime.core.data.NominalValue) NominalValueRepresentation(org.knime.base.node.mine.treeensemble2.data.NominalValueRepresentation) LinkedHashMap(java.util.LinkedHashMap) TreeNominalColumnMetaData(org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnMetaData) DataColumnSpec(org.knime.core.data.DataColumnSpec) DoubleValue(org.knime.core.data.DoubleValue) PredictorRecord(org.knime.base.node.mine.treeensemble2.data.PredictorRecord) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell)

Example 2 with TreeNominalColumnMetaData

use of org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnMetaData in project knime-core by knime.

the class LiteralConditionParser method handleSimpleSetPredicate.

private TreeNodeColumnCondition handleSimpleSetPredicate(final SimpleSetPredicate simpleSetPred, final boolean acceptsMissings) {
    String field = simpleSetPred.getField();
    CheckUtils.checkArgument(m_metaDataMapper.isNominal(field), "The field \"%s\" is not nominal but currently only nominal fields can be used for SimpleSetPredicates", field);
    NominalAttributeColumnHelper colHelper = m_metaDataMapper.getNominalColumnHelper(field);
    TreeNominalColumnMetaData metaData = colHelper.getMetaData();
    boolean isInSet = simpleSetPred.getBooleanOperator().equals(SimpleSetPredicate.BooleanOperator.IS_IN);
    return new TreeNodeNominalBinaryCondition(metaData, parseValuesMask(simpleSetPred, colHelper), isInSet, acceptsMissings);
}
Also used : TreeNominalColumnMetaData(org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnMetaData) TreeNodeNominalBinaryCondition(org.knime.base.node.mine.treeensemble2.model.TreeNodeNominalBinaryCondition)

Example 3 with TreeNominalColumnMetaData

use of org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnMetaData in project knime-core by knime.

the class NominalMultiwaySplitCandidate method getChildConditions.

/**
 * {@inheritDoc}
 */
@Override
public TreeNodeNominalCondition[] getChildConditions() {
    TreeNominalColumnMetaData columnMeta = getColumnData().getMetaData();
    NominalValueRepresentation[] values = columnMeta.getValues();
    final int lengthNonMissing = values[values.length - 1].getNominalValue().equals(NominalValueRepresentation.MISSING_VALUE) ? values.length - 1 : values.length;
    List<TreeNodeCondition> resultList = new ArrayList<TreeNodeCondition>(lengthNonMissing);
    for (int i = 0; i < lengthNonMissing; i++) {
        if (m_sumWeightsAttributes[i] >= TreeColumnData.EPSILON) {
            resultList.add(new TreeNodeNominalCondition(columnMeta, i, i == m_missingsGoToChildIdx));
        }
    }
    return resultList.toArray(new TreeNodeNominalCondition[resultList.size()]);
}
Also used : TreeNominalColumnMetaData(org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnMetaData) TreeNodeNominalCondition(org.knime.base.node.mine.treeensemble2.model.TreeNodeNominalCondition) ArrayList(java.util.ArrayList) NominalValueRepresentation(org.knime.base.node.mine.treeensemble2.data.NominalValueRepresentation) TreeNodeCondition(org.knime.base.node.mine.treeensemble2.model.TreeNodeCondition)

Example 4 with TreeNominalColumnMetaData

use of org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnMetaData in project knime-core by knime.

the class NominalAttributeColumnHelper method createMetaData.

/**
 * {@inheritDoc}
 */
@Override
protected TreeNominalColumnMetaData createMetaData(final DataColumnSpec nominalColSpec) {
    DataColumnDomain domain = nominalColSpec.getDomain();
    CheckUtils.checkArgument(domain.hasValues(), "The data dictionary doesn't contain domain" + " information for column \"%s\".", nominalColSpec);
    NominalValueRepresentation[] nomVals = NominalColumnHelperUtil.extractNomValReps(domain.getValues());
    return new TreeNominalColumnMetaData(nominalColSpec.getName(), nomVals);
}
Also used : TreeNominalColumnMetaData(org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnMetaData) DataColumnDomain(org.knime.core.data.DataColumnDomain) NominalValueRepresentation(org.knime.base.node.mine.treeensemble2.data.NominalValueRepresentation)

Aggregations

TreeNominalColumnMetaData (org.knime.base.node.mine.treeensemble2.data.TreeNominalColumnMetaData)4 NominalValueRepresentation (org.knime.base.node.mine.treeensemble2.data.NominalValueRepresentation)3 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 PredictorRecord (org.knime.base.node.mine.treeensemble2.data.PredictorRecord)1 TreeNodeCondition (org.knime.base.node.mine.treeensemble2.model.TreeNodeCondition)1 TreeNodeNominalBinaryCondition (org.knime.base.node.mine.treeensemble2.model.TreeNodeNominalBinaryCondition)1 TreeNodeNominalCondition (org.knime.base.node.mine.treeensemble2.model.TreeNodeNominalCondition)1 DataCell (org.knime.core.data.DataCell)1 DataColumnDomain (org.knime.core.data.DataColumnDomain)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataType (org.knime.core.data.DataType)1 DoubleValue (org.knime.core.data.DoubleValue)1 NominalValue (org.knime.core.data.NominalValue)1