Search in sources :

Example 56 with DataColumnSpecCreator

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();
}
Also used : JDKRandomGenerator(org.apache.commons.math.random.JDKRandomGenerator) TreeType(org.knime.base.node.mine.treeensemble2.model.AbstractTreeEnsembleModel.TreeType) Arrays(java.util.Arrays) RandomData(org.apache.commons.math.random.RandomData) RowKey(org.knime.core.data.RowKey) RandomDataImpl(org.apache.commons.math.random.RandomDataImpl) DoubleCell(org.knime.core.data.def.DoubleCell) Lists(com.google.common.collect.Lists) TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) MissingCell(org.knime.core.data.MissingCell) Doubles(com.google.common.primitives.Doubles) StringCell(org.knime.core.data.def.StringCell) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) StringCell(org.knime.core.data.def.StringCell) RowKey(org.knime.core.data.RowKey) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 57 with DataColumnSpecCreator

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();
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell)

Example 58 with DataColumnSpecCreator

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;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) RowKey(org.knime.core.data.RowKey) MissingCell(org.knime.core.data.MissingCell) StringCell(org.knime.core.data.def.StringCell)

Example 59 with DataColumnSpecCreator

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);
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) RowKey(org.knime.core.data.RowKey) MissingCell(org.knime.core.data.MissingCell) DoubleCell(org.knime.core.data.def.DoubleCell)

Example 60 with DataColumnSpecCreator

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());
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) DataRow(org.knime.core.data.DataRow) DataColumnSpec(org.knime.core.data.DataColumnSpec) Random(java.util.Random) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) Before(org.junit.Before)

Aggregations

DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)267 DataColumnSpec (org.knime.core.data.DataColumnSpec)210 DataTableSpec (org.knime.core.data.DataTableSpec)132 DataCell (org.knime.core.data.DataCell)92 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)77 DataType (org.knime.core.data.DataType)74 DataRow (org.knime.core.data.DataRow)73 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)57 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)51 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)48 ArrayList (java.util.ArrayList)46 DoubleCell (org.knime.core.data.def.DoubleCell)45 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)44 StringCell (org.knime.core.data.def.StringCell)29 BufferedDataTable (org.knime.core.node.BufferedDataTable)23 DoubleValue (org.knime.core.data.DoubleValue)22 HashSet (java.util.HashSet)19 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)17 DataColumnDomain (org.knime.core.data.DataColumnDomain)16 DefaultRow (org.knime.core.data.def.DefaultRow)16