use of org.knime.core.data.DataColumnSpecCreator 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.DataColumnSpecCreator in project knime-core by knime.
the class TestDataGenerator method createNumericTargetColumn.
public static TreeTargetNumericColumnData createNumericTargetColumn(final String dataCSV) {
double[] values = asDataArray(dataCSV);
DataColumnSpec targetSpec = new DataColumnSpecCreator("test-target", DoubleCell.TYPE).createSpec();
TreeTargetNumericColumnDataCreator targetCreator = new TreeTargetNumericColumnDataCreator(targetSpec);
for (int i = 0; i < values.length; i++) {
RowKey rowKey = RowKey.createRowKey((long) i);
targetCreator.add(rowKey, new DoubleCell(values[i]));
}
return targetCreator.createColumnData();
}
use of org.knime.core.data.DataColumnSpecCreator 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.DataColumnSpecCreator in project knime-core by knime.
the class TreeNumericColumnDataTest method createNumericColumnData.
public static TreeOrdinaryNumericColumnData createNumericColumnData(final TreeEnsembleLearnerConfiguration config, final double[] data, final String name, final int attributeIndex) {
DataColumnSpec colSpec = new DataColumnSpecCreator(name, DoubleCell.TYPE).createSpec();
TreeOrdinaryNumericColumnDataCreator colCreator = new TreeOrdinaryNumericColumnDataCreator(colSpec);
for (int i = 0; i < data.length; i++) {
final RowKey key = RowKey.createRowKey(i);
if (Double.isNaN(data[i])) {
colCreator.add(key, new MissingCell(null));
} else {
colCreator.add(key, new DoubleCell(data[i]));
}
}
return colCreator.createColumnData(attributeIndex, config);
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class MedianTableTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
Random random = new Random(37);
DataColumnSpec[] colSpecs = new DataColumnSpec[] { new DataColumnSpecCreator("AscendingDouble", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("DescendingDouble", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("ThreeValuesSingleMedian", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("ThreeValuesDifferentMedian", DoubleCell.TYPE).createSpec() // new DataColumnSpecCreator("FourValuesSingleMedian", DoubleCell.TYPE).createSpec(),
// new DataColumnSpecCreator("FourValuesDifferentMedian", DoubleCell.TYPE).createSpec()
};
DataTableSpec spec = new DataTableSpec(colSpecs);
final BufferedDataContainer container = EXEC_CONTEXT.createDataContainer(spec);
try {
int count = 100;
for (int i = 0; i < count; ++i) {
int col = 0;
DataCell[] rowVals = new DataCell[colSpecs.length];
rowVals[col++] = new DoubleCell(i);
rowVals[col++] = new DoubleCell(count - i - 1);
rowVals[col++] = i == 4 ? DataType.getMissingCell() : new DoubleCell(i < count / 2 ? 0 : i * 2 >= count + 2 ? 4 : 1);
rowVals[col++] = new DoubleCell(i < count / 2 ? 0 : i * 2 >= count + 2 ? 4 : 1);
container.addRowToTable(new DefaultRow(Integer.toString(i), rowVals));
}
} finally {
container.close();
}
smallTable = container.getTable();
NodeLogger.getLogger(getClass()).debug("Contents of test table:");
for (DataRow row : smallTable) {
StringBuilder buf = new StringBuilder();
for (DataCell dataCell : row) {
buf.append(dataCell + "\t");
}
NodeLogger.getLogger(getClass()).debug(buf.toString());
}
}
Aggregations