use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class RegressionPredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
public PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
PMMLPortObject port = (PMMLPortObject) inData[0];
List<Node> models = port.getPMMLValue().getModels(PMMLModelType.GeneralRegressionModel);
if (models.isEmpty()) {
LOGGER.warn("No regression models in the input PMML.");
@SuppressWarnings("deprecation") org.knime.base.node.mine.regression.predict.RegressionPredictorNodeModel regrPredictor = new org.knime.base.node.mine.regression.predict.RegressionPredictorNodeModel();
@SuppressWarnings("deprecation") PortObject[] regrPredOut = regrPredictor.execute(inData, exec);
if (regrPredOut.length > 0 && regrPredOut[0] instanceof BufferedDataTable) {
BufferedDataTable regrPredOutTable = (BufferedDataTable) regrPredOut[0];
// replace name of prediction column (the last column of regrPredOutTable)
return new PortObject[] { adjustSpecOfRegressionPredictorTable(regrPredOutTable, inData, exec) };
} else {
return regrPredOut;
}
}
PMMLGeneralRegressionTranslator trans = new PMMLGeneralRegressionTranslator();
port.initializeModelTranslator(trans);
BufferedDataTable data = (BufferedDataTable) inData[1];
DataTableSpec spec = data.getDataTableSpec();
ColumnRearranger c = createRearranger(trans.getContent(), port.getSpec(), spec);
BufferedDataTable out = exec.createColumnRearrangeTable(data, c, exec);
return new BufferedDataTable[] { out };
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class BitVectorGeneratorNodeModel method createBitVectorsFromNumericData.
private BufferedDataTable[] createBitVectorsFromNumericData(final BufferedDataTable data, final ExecutionContext exec) throws CanceledExecutionException {
DataColumnSpec colSpec = createNumericOutputSpec(data.getDataTableSpec());
// get the indices for included columns
List<Integer> colIndices = new ArrayList<Integer>();
for (String colName : m_includedColumns.getIncludeList()) {
int index = data.getDataTableSpec().findColumnIndex(colName);
if (index < 0) {
throw new IllegalArgumentException("Column " + colName + " is not available in " + "current data. Please re-configure the node.");
}
colIndices.add(index);
}
// calculate bits from numeric data
if (m_useMean) {
// either from a percentage of the mean
double[] meanValues = new double[0];
double meanFactor = m_meanPercentage / 100.0;
meanValues = calculateMeanValues(data);
m_factory = new Numeric2BitVectorMeanCellFactory(colSpec, meanValues, meanFactor, colIndices);
} else {
// or dependend on fixed threshold
m_factory = new Numeric2BitVectorThresholdCellFactory(colSpec, m_threshold, colIndices);
}
ColumnRearranger c = new ColumnRearranger(data.getDataTableSpec());
c.append(m_factory);
if (m_replace) {
List<String> includeList = m_includedColumns.getIncludeList();
c.remove(includeList.toArray(new String[includeList.size()]));
}
BufferedDataTable out = exec.createColumnRearrangeTable(data, c, exec);
return new BufferedDataTable[] { out };
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class AutoBinner method calcDomainBoundsIfNeccessary.
/**
* Determines the per column min/max values of the given data if not already
* present in the domain.
* @param data the data
* @param exec the execution context
* @param recalcValuesFor The columns
* @return The data with extended domain information
* @throws InvalidSettingsException
* @throws CanceledExecutionException
*/
public BufferedDataTable calcDomainBoundsIfNeccessary(final BufferedDataTable data, final ExecutionContext exec, final List<String> recalcValuesFor) throws InvalidSettingsException, CanceledExecutionException {
if (null == recalcValuesFor || recalcValuesFor.isEmpty()) {
return data;
}
List<Integer> valuesI = new ArrayList<Integer>();
for (String colName : recalcValuesFor) {
DataColumnSpec colSpec = data.getDataTableSpec().getColumnSpec(colName);
if (!colSpec.getType().isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("Can only process numeric " + "data. The column \"" + colSpec.getName() + "\" is not numeric.");
}
if (recalcValuesFor.contains(colName) && !colSpec.getDomain().hasBounds()) {
valuesI.add(data.getDataTableSpec().findColumnIndex(colName));
}
}
if (valuesI.isEmpty()) {
return data;
}
Map<Integer, Double> min = new HashMap<Integer, Double>();
Map<Integer, Double> max = new HashMap<Integer, Double>();
for (int col : valuesI) {
min.put(col, Double.MAX_VALUE);
max.put(col, Double.MIN_VALUE);
}
int c = 0;
for (DataRow row : data) {
c++;
exec.checkCanceled();
exec.setProgress(c / (double) data.getRowCount());
for (int col : valuesI) {
double val = ((DoubleValue) row.getCell(col)).getDoubleValue();
if (min.get(col) > val) {
min.put(col, val);
}
if (max.get(col) < val) {
min.put(col, val);
}
}
}
List<DataColumnSpec> newColSpecList = new ArrayList<DataColumnSpec>();
int cc = 0;
for (DataColumnSpec columnSpec : data.getDataTableSpec()) {
if (recalcValuesFor.contains(columnSpec.getName())) {
DataColumnSpecCreator specCreator = new DataColumnSpecCreator(columnSpec);
DataColumnDomainCreator domainCreator = new DataColumnDomainCreator(new DoubleCell(min.get(cc)), new DoubleCell(max.get(cc)));
specCreator.setDomain(domainCreator.createDomain());
DataColumnSpec newColSpec = specCreator.createSpec();
newColSpecList.add(newColSpec);
} else {
newColSpecList.add(columnSpec);
}
cc++;
}
DataTableSpec spec = new DataTableSpec(newColSpecList.toArray(new DataColumnSpec[0]));
BufferedDataTable newDataTable = exec.createSpecReplacerTable(data, spec);
return newDataTable;
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class AutoBinnerLearnNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
BufferedDataTable data = (BufferedDataTable) inObjects[0];
AutoBinner binner = new AutoBinner(m_settings);
BufferedDataTable inData = binner.calcDomainBoundsIfNeccessary(data, exec, Arrays.asList(m_settings.getTargetColumn()));
PMMLPreprocDiscretize op = binner.execute(inData, exec);
AutoBinnerApply applier = new AutoBinnerApply();
BufferedDataTable outData = applier.execute(op, inData, exec);
return new PortObject[] { outData, new PMMLDiscretizePreprocPortObject(op) };
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class AutoBinnerLearnNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
BufferedDataTable data = (BufferedDataTable) inObjects[0];
AutoBinner binner = new AutoBinner(m_settings);
BufferedDataTable inData = binner.calcDomainBoundsIfNeccessary(data, exec, Arrays.asList(m_settings.getTargetColumn()));
PMMLPreprocDiscretize op = binner.execute(inData, exec);
AutoBinnerApply applier = new AutoBinnerApply();
BufferedDataTable outData = applier.execute(op, inData, exec);
return new PortObject[] { outData, new PMMLDiscretizePreprocPortObject(op) };
}
Aggregations