use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class PolyRegLearnerNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
String[] selectedCols = computeSelectedColumns(tableSpec);
m_columnNames = selectedCols;
for (String colName : selectedCols) {
DataColumnSpec dcs = tableSpec.getColumnSpec(colName);
if (dcs == null) {
throw new InvalidSettingsException("Selected column '" + colName + "' does not exist in input table");
}
if (!dcs.getType().isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("Selected column '" + dcs.getName() + "' from the input table is not a numeric column.");
}
}
if (m_settings.getTargetColumn() == null) {
throw new InvalidSettingsException("No target column selected");
}
if (tableSpec.findColumnIndex(m_settings.getTargetColumn()) == -1) {
throw new InvalidSettingsException("Target column '" + m_settings.getTargetColumn() + "' does not exist.");
}
DataColumnSpecCreator crea = new DataColumnSpecCreator("PolyReg prediction", DoubleCell.TYPE);
DataColumnSpec col1 = crea.createSpec();
crea = new DataColumnSpecCreator("Prediction Error", DoubleCell.TYPE);
DataColumnSpec col2 = crea.createSpec();
return new PortObjectSpec[] { createModelSpec(pmmlSpec, tableSpec), AppendedColumnTable.getTableSpec(tableSpec, col1, col2), STATS_SPEC };
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class PolyRegLearnerNodeModel method getCellFactory.
private CellFactory getCellFactory(final int dependentIndex) {
final int degree = m_settings.getDegree();
return new CellFactory() {
@Override
public DataCell[] getCells(final DataRow row) {
double sum = m_betas[0];
int betaCount = 1;
double y = 0;
for (int col = 0; col < row.getNumCells(); col++) {
if ((col == dependentIndex || m_colSelected[col]) && row.getCell(col).isMissing()) {
switch(m_settings.getMissingValueHandling()) {
case ignore:
return new DataCell[] { DataType.getMissingCell(), DataType.getMissingCell() };
case fail:
throw new IllegalStateException("Should failed earlier!");
default:
throw new UnsupportedOperationException("Not supported missing handling strategy: " + m_settings.getMissingValueHandling());
}
}
if ((col != dependentIndex) && m_colSelected[col]) {
final double value = ((DoubleValue) row.getCell(col)).getDoubleValue();
double poly = 1;
for (int d = 1; d <= degree; d++) {
poly *= value;
sum += m_betas[betaCount++] * poly;
}
} else if (col == dependentIndex) {
y = ((DoubleValue) row.getCell(col)).getDoubleValue();
}
}
double err = Math.abs(sum - y);
m_squaredError += err * err;
return new DataCell[] { new DoubleCell(sum), new DoubleCell(err) };
}
@Override
public DataColumnSpec[] getColumnSpecs() {
DataColumnSpecCreator crea = new DataColumnSpecCreator("PolyReg prediction", DoubleCell.TYPE);
DataColumnSpec col1 = crea.createSpec();
crea = new DataColumnSpecCreator("Prediction Error", DoubleCell.TYPE);
DataColumnSpec col2 = crea.createSpec();
return new DataColumnSpec[] { col1, col2 };
}
@Override
public void setProgress(final int curRowNr, final int rowCount, final RowKey lastKey, final ExecutionMonitor execMon) {
// do nothing
}
};
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class ClusterNodeModel method createAppendedSpec.
private DataTableSpec createAppendedSpec(final DataTableSpec originalSpec) {
// determine the possible values of the appended column
DataCell[] possibleValues = new DataCell[m_nrOfClusters.getIntValue()];
for (int i = 0; i < m_nrOfClusters.getIntValue(); i++) {
DataCell key = new StringCell(CLUSTER + i);
possibleValues[i] = key;
}
// create the domain
// 1) guess an unused name for the new column (fixes bug #1022)
String colNameGuess = "Cluster";
int uniqueNr = 0;
while (originalSpec.getColumnSpec(colNameGuess) != null) {
uniqueNr++;
colNameGuess = "Cluster_" + uniqueNr;
}
// 2) create spec
DataColumnDomainCreator domainCreator = new DataColumnDomainCreator(possibleValues);
DataColumnSpecCreator creator = new DataColumnSpecCreator(colNameGuess, StringCell.TYPE);
creator.setDomain(domainCreator.createDomain());
// create the appended column spec
DataColumnSpec labelColSpec = creator.createSpec();
return new DataTableSpec(originalSpec, new DataTableSpec(labelColSpec));
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class ClusterNodeModel method createClusterCentersSpec.
private DataTableSpec createClusterCentersSpec(final DataTableSpec spec) {
// Create spec for cluster center table
DataTableSpecCreator clusterCenterSpecCreator = new DataTableSpecCreator();
for (int i = 0; i < m_dimension; i++) {
if (!m_ignoreColumn[i]) {
clusterCenterSpecCreator.addColumns(new DataColumnSpecCreator(spec.getColumnSpec(i).getName(), DoubleCell.TYPE).createSpec());
}
}
clusterCenterSpecCreator.dropAllDomains();
return clusterCenterSpecCreator.createSpec();
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class HierarchicalClusterNodeModel method generateOutSpec.
/**
* Generate output spec based on input spec (appends column).
*/
private static DataTableSpec generateOutSpec(final DataTableSpec inSpec) {
int oldColCount = inSpec.getNumColumns();
int colCount = oldColCount + 1;
DataColumnSpec[] colSpecs = new DataColumnSpec[colCount];
for (int i = 0; i < oldColCount; i++) {
colSpecs[i] = inSpec.getColumnSpec(i);
}
// the additional column contains the cluster information
DataColumnSpecCreator colspeccreator = new DataColumnSpecCreator("Cluster", StringCell.TYPE);
colSpecs[oldColCount] = colspeccreator.createSpec();
return new DataTableSpec(colSpecs);
}
Aggregations