use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class AdapterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
if (getNrInPorts() == 0 && getNrOutPorts() == 1) {
// assume simple source node with one table output
BufferedDataContainer cnt = exec.createDataContainer(createDefaultOutputSpec());
cnt.addRowToTable(new DefaultRow(RowKey.createRowKey(0), new DataCell[] { new StringCell("Cell-1.1"), new IntCell(12), new DoubleCell(1.3) }));
cnt.addRowToTable(new DefaultRow(RowKey.createRowKey(1), new DataCell[] { new StringCell("Cell-2.1"), new IntCell(22), new DoubleCell(2.3) }));
cnt.addRowToTable(new DefaultRow(RowKey.createRowKey(2), new DataCell[] { new StringCell("Cell-3.1"), new IntCell(32), new DoubleCell(3.3) }));
cnt.close();
return new BufferedDataTable[] { cnt.getTable() };
}
return inObjects;
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class SubgroupMinerModel2 method createAssociationRulesOutput.
private BufferedDataTable createAssociationRulesOutput(final DataTableSpec inputSpec, final ExecutionContext exec, final AprioriAlgorithm apriori, final List<DataCell> nameMapping) {
DataTableSpec outSpec = createAssociationRulesSpec(inputSpec);
BufferedDataContainer ruleRows = exec.createDataContainer(outSpec);
assert nameMapping != null;
List<AssociationRule> associationRules = apriori.getAssociationRules(m_confidence.getDoubleValue());
// for every association rule
int rowKeyCounter = 0;
for (AssociationRule r : associationRules) {
// get the support
double support = r.getSupport();
// get the confidence
double confidence = r.getConfidence();
// get lift
double lift = r.getLift();
// get the antecedence (which is one item) -> cell
FrequentItemSet antecedent = r.getAntecedent();
// get the consequence
FrequentItemSet consequent = r.getConsequent();
DataCell[] allCells = new DataCell[6];
allCells[0] = new DoubleCell(support);
allCells[1] = new DoubleCell(confidence);
allCells[2] = new DoubleCell(lift);
// consequent is always only one item -> access with get(0) ok
if (nameMapping.size() > consequent.getItems().get(0)) {
allCells[3] = nameMapping.get(consequent.getItems().get(0));
} else {
allCells[3] = new StringCell("Item" + consequent.getItems().get(0));
}
allCells[4] = new StringCell("<---");
Set<DataCell> allcells = new HashSet<DataCell>();
for (int i = 0; i < antecedent.getItems().size() && i < m_maxItemSetLength.getIntValue() + 5; i++) {
if (nameMapping.size() > antecedent.getItems().get(i)) {
allcells.add(nameMapping.get(antecedent.getItems().get(i)));
} else {
allcells.add(new StringCell("Item" + antecedent.getItems().get(i)));
}
}
allCells[5] = CollectionCellFactory.createSetCell(allcells);
if (antecedent.getItems().size() > 0) {
DataRow row = new DefaultRow("rule" + (rowKeyCounter++), allCells);
ruleRows.addRowToTable(row);
}
}
ruleRows.close();
return ruleRows.getTable();
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class SVMPredictor method getCells.
/**
* {@inheritDoc}
*/
@Override
public DataCell[] getCells(final DataRow row) {
ArrayList<Double> values = new ArrayList<Double>();
for (int i = 0; i < m_colindices.length; i++) {
if (row.getCell(m_colindices[i]).isMissing()) {
if (m_appendProbabilities) {
DataCell[] ret = new DataCell[1 + m_svms.length];
Arrays.fill(ret, new MissingCell("Missing value in input data."));
return ret;
}
return new DataCell[] { DataType.getMissingCell() };
}
DoubleValue dv = (DoubleValue) row.getCell(m_colindices[i]);
values.add(dv.getDoubleValue());
}
String classvalue = doPredict(values);
if (m_appendProbabilities) {
DataCell[] ret = new DataCell[m_svms.length + 1];
double[] probabilities = computeProbabilities(values);
assert ret.length == probabilities.length + 1 : ret.length + " vs. " + (probabilities.length + 1);
for (int i = ret.length - 1; i-- > 0; ) {
ret[i] = new DoubleCell(probabilities[i]);
}
ret[probabilities.length] = new StringCell(classvalue);
return ret;
}
return new DataCell[] { new StringCell(classvalue) };
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class SVMPredictor method getColumnSpecs.
/**
* {@inheritDoc}
*/
@Override
public DataColumnSpec[] getColumnSpecs() {
DataColumnSpecCreator colspeccreator = new DataColumnSpecCreator(m_predictionColumnName, StringCell.TYPE);
if (m_appendProbabilities) {
final DataColumnSpec[] ret = new DataColumnSpec[m_svms.length + 1];
PredictorHelper ph = PredictorHelper.getInstance();
final DataColumnSpecCreator creator = new DataColumnSpecCreator("Dummy", DoubleCell.TYPE);
creator.setDomain(new DataColumnDomainCreator(new DoubleCell(0), new DoubleCell(1)).createDomain());
for (int i = m_svms.length; i-- > 0; ) {
String name = ph.probabilityColumnName(m_trainingColumn, m_svms[i].getPositive(), m_suffix);
creator.setName(name);
ret[i] = creator.createSpec();
}
ret[m_svms.length] = colspeccreator.createSpec();
return ret;
}
return new DataColumnSpec[] { colspeccreator.createSpec() };
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class PredictorHelper method createOutTableSpec.
/**
* Computes the output table's specifaction based on common node settings.
*
* @param dataSpec The input table {@link DataColumnSpec}.
* @param modelSpec The model {@link PMMLPortObjectSpec}.
* @param addProbs Add the probability columns?
* @param predictionCol Custom name of the prediction column.
* @param shouldOverride Should we use that name?
* @param suffix Suffix for probability columns.
* @return The output table {@link DataTableSpec}.
* @throws InvalidSettingsException Invalid settings for the prediction column name.
*/
public DataTableSpec createOutTableSpec(final PortObjectSpec dataSpec, final PortObjectSpec modelSpec, final boolean addProbs, final String predictionCol, final boolean shouldOverride, final String suffix) throws InvalidSettingsException {
CheckUtils.checkSettingNotNull(predictionCol, "Prediction column name cannot be null");
CheckUtils.checkSetting(!predictionCol.trim().isEmpty(), "Prediction column name cannot be empty");
List<DataCell> predValues = null;
if (addProbs) {
predValues = getPredictionValues((PMMLPortObjectSpec) modelSpec);
if (predValues == null) {
// no out spec can be determined
return null;
}
}
int numCols = (predValues == null ? 0 : predValues.size()) + 1;
DataTableSpec inSpec = (DataTableSpec) dataSpec;
DataColumnSpec[] newCols = new DataColumnSpec[numCols];
/* Set bar renderer and domain [0,1] as default for the double cells
* containing the distribution */
// DataColumnProperties propsRendering = new DataColumnProperties(
// Collections.singletonMap(
// DataValueRenderer.PROPERTY_PREFERRED_RENDERER,
// DoubleBarRenderer.DESCRIPTION));
DataColumnDomain domain = new DataColumnDomainCreator(new DoubleCell(0.0), new DoubleCell(1.0)).createDomain();
String trainingColumnName = ((PMMLPortObjectSpec) modelSpec).getTargetFields().iterator().next();
// add all distribution columns
for (int i = 0; i < numCols - 1; i++) {
assert predValues != null;
DataColumnSpecCreator colSpecCreator = new DataColumnSpecCreator(probabilityColumnName(trainingColumnName, predValues.get(i).toString(), suffix), DoubleCell.TYPE);
// colSpecCreator.setProperties(propsRendering);
colSpecCreator.setDomain(domain);
newCols[i] = colSpecCreator.createSpec();
}
// add the prediction column
String predictionColumnName = computePredictionColumnName(predictionCol, shouldOverride, trainingColumnName);
newCols[numCols - 1] = new DataColumnSpecCreator(predictionColumnName, StringCell.TYPE).createSpec();
DataTableSpec newColSpec = new DataTableSpec(newCols);
return new DataTableSpec(inSpec, newColSpec);
}
Aggregations