Search in sources :

Example 56 with DoubleCell

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;
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell)

Example 57 with DoubleCell

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();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) FrequentItemSet(org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSet) DataRow(org.knime.core.data.DataRow) AssociationRule(org.knime.base.node.mine.subgroupminer.freqitemset.AssociationRule) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) HashSet(java.util.HashSet)

Example 58 with DoubleCell

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) };
}
Also used : MissingCell(org.knime.core.data.MissingCell) DoubleValue(org.knime.core.data.DoubleValue) StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) DataCell(org.knime.core.data.DataCell)

Example 59 with DoubleCell

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() };
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) PredictorHelper(org.knime.base.node.mine.util.PredictorHelper) DoubleCell(org.knime.core.data.def.DoubleCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 60 with DoubleCell

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);
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DialogComponentString(org.knime.core.node.defaultnodesettings.DialogComponentString)

Aggregations

DoubleCell (org.knime.core.data.def.DoubleCell)189 DataCell (org.knime.core.data.DataCell)129 IntCell (org.knime.core.data.def.IntCell)67 DefaultRow (org.knime.core.data.def.DefaultRow)66 StringCell (org.knime.core.data.def.StringCell)65 DataRow (org.knime.core.data.DataRow)57 DataTableSpec (org.knime.core.data.DataTableSpec)55 ArrayList (java.util.ArrayList)42 DataColumnSpec (org.knime.core.data.DataColumnSpec)42 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)41 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)39 RowKey (org.knime.core.data.RowKey)37 DoubleValue (org.knime.core.data.DoubleValue)35 BufferedDataTable (org.knime.core.node.BufferedDataTable)28 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)26 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)22 DataType (org.knime.core.data.DataType)20 LinkedHashMap (java.util.LinkedHashMap)17 HashMap (java.util.HashMap)13 Point (java.awt.Point)12