use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class RegressionTreeModel method createLearnAttributeRow.
public DataRow createLearnAttributeRow(final DataRow learnRow, final DataTableSpec learnSpec) {
final TreeType type = getType();
switch(type) {
case Ordinary:
return learnRow;
case BitVector:
DataCell c = learnRow.getCell(0);
if (c.isMissing()) {
return null;
}
BitVectorValue bv = (BitVectorValue) c;
final long length = bv.length();
int nrAttributes = getMetaData().getNrAttributes();
if (length != nrAttributes) {
// TODO indicate error message
return null;
}
DataCell trueCell = new StringCell("1");
DataCell falseCell = new StringCell("0");
DataCell[] cells = new DataCell[nrAttributes];
for (int i = 0; i < nrAttributes; i++) {
cells[i] = bv.get(i) ? trueCell : falseCell;
}
return new DefaultRow(learnRow.getKey(), cells);
case ByteVector:
DataCell cell = learnRow.getCell(0);
if (cell.isMissing()) {
return null;
}
ByteVectorValue byteVector = (ByteVectorValue) cell;
final long bvLength = byteVector.length();
int nrAttr = getMetaData().getNrAttributes();
if (bvLength != nrAttr) {
return null;
}
DataCell[] bvCells = new DataCell[nrAttr];
for (int i = 0; i < nrAttr; i++) {
bvCells[i] = new IntCell(byteVector.get(i));
}
return new DefaultRow(learnRow.getKey(), bvCells);
default:
throw new IllegalStateException("Type unknown (not implemented): " + type);
}
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class TreeEnsembleModel method createLearnAttributeRow.
public DataRow createLearnAttributeRow(final DataRow learnRow, final DataTableSpec learnSpec) {
final TreeType type = getType();
switch(type) {
case Ordinary:
return learnRow;
case BitVector:
DataCell c = learnRow.getCell(0);
if (c.isMissing()) {
return null;
}
BitVectorValue bv = (BitVectorValue) c;
final long length = bv.length();
int nrAttributes = getMetaData().getNrAttributes();
if (length != nrAttributes) {
// TODO indicate error message
return null;
}
DataCell trueCell = new StringCell("1");
DataCell falseCell = new StringCell("0");
DataCell[] cells = new DataCell[nrAttributes];
for (int i = 0; i < nrAttributes; i++) {
cells[i] = bv.get(i) ? trueCell : falseCell;
}
return new DefaultRow(learnRow.getKey(), cells);
case ByteVector:
DataCell cell = learnRow.getCell(0);
if (cell.isMissing()) {
return null;
}
ByteVectorValue byteVector = (ByteVectorValue) cell;
final long bvLength = byteVector.length();
int nrAttr = getMetaData().getNrAttributes();
if (bvLength != nrAttr) {
return null;
}
DataCell[] bvCells = new DataCell[nrAttr];
for (int i = 0; i < nrAttr; i++) {
bvCells[i] = new IntCell(byteVector.get(i));
}
return new DefaultRow(learnRow.getKey(), bvCells);
default:
throw new IllegalStateException("Type unknown (not implemented): " + type);
}
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class TestDataGenerator method createNominalTargetColumn.
public static TreeTargetNominalColumnData createNominalTargetColumn(final String[] values) {
DataColumnDomainCreator dc = new DataColumnDomainCreator(Arrays.stream(values).distinct().map(s -> new StringCell(s)).toArray(i -> new StringCell[i]));
DataColumnSpecCreator specCreator = new DataColumnSpecCreator("test-target", StringCell.TYPE);
specCreator.setDomain(dc.createDomain());
DataColumnSpec targetSpec = specCreator.createSpec();
TreeTargetColumnDataCreator targetCreator = new TreeTargetNominalColumnDataCreator(targetSpec);
for (int i = 0; i < values.length; i++) {
RowKey rowKey = RowKey.createRowKey((long) i);
targetCreator.add(rowKey, new StringCell(values[i]));
}
return (TreeTargetNominalColumnData) targetCreator.createColumnData();
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class TestDataGenerator method createNominalAttributeColumn.
public TreeNominalColumnData createNominalAttributeColumn(final String[] values, final String name, final int attributeIndex) {
DataColumnSpec colSpec = new DataColumnSpecCreator(name, StringCell.TYPE).createSpec();
TreeNominalColumnDataCreator colCreator = new TreeNominalColumnDataCreator(colSpec);
for (int i = 0; i < values.length; i++) {
RowKey rowKey = RowKey.createRowKey((long) i);
if (values[i].equals("?")) {
colCreator.add(rowKey, new MissingCell(null));
} else {
colCreator.add(rowKey, new StringCell(values[i]));
}
}
TreeNominalColumnData col = colCreator.createColumnData(0, m_config);
col.getMetaData().setAttributeIndex(attributeIndex);
return col;
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class JoinedTableTest method getRandomRow.
private static final DataRow getRandomRow(final String id) {
DataCell[] cells = new DataCell[3];
cells[0] = new StringCell(id + "-" + RAND.nextInt(100));
cells[1] = new IntCell(RAND.nextInt());
cells[2] = new DoubleCell(RAND.nextDouble());
return new DefaultRow(id, cells);
}
Aggregations