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);
}
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);
}
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()]);
}
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);
}
Aggregations