Search in sources :

Example 96 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class LogRegLearnerNodeDialogPane method createTargetOptionsPanel.

/**
 * Create options panel for the target.
 */
private JPanel createTargetOptionsPanel() {
    JPanel p = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.BASELINE_LEADING;
    c.insets = new Insets(5, 5, 0, 0);
    p.add(new JLabel("Target Column:"), c);
    c.gridx++;
    @SuppressWarnings("unchecked") final ColumnSelectionPanel columnSelectionPanel = new ColumnSelectionPanel(new EmptyBorder(0, 0, 0, 0), NominalValue.class);
    m_selectionPanel = columnSelectionPanel;
    m_selectionPanel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            updateTargetCategories((DataCell) m_targetReferenceCategory.getSelectedItem());
        }
    });
    p.add(m_selectionPanel, c);
    c.gridx = 0;
    c.gridy++;
    p.add(new JLabel("Reference Category:"), c);
    c.gridx++;
    m_targetReferenceCategory = new JComboBox<>();
    p.add(m_targetReferenceCategory, c);
    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 3;
    c.weightx = 1;
    m_notSortTarget = new JCheckBox("Use order from target column domain (only relevant for output representation)");
    p.add(m_notSortTarget, c);
    m_selectionPanel.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            Object selected = e.getItem();
            if (selected instanceof DataColumnSpec) {
                m_filterPanel.resetHiding();
                m_filterPanel.hideNames((DataColumnSpec) selected);
            }
        }
    });
    return p;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) DataColumnSpec(org.knime.core.data.DataColumnSpec) ActionListener(java.awt.event.ActionListener) DataCell(org.knime.core.data.DataCell) ItemListener(java.awt.event.ItemListener) ColumnSelectionPanel(org.knime.core.node.util.ColumnSelectionPanel) EmptyBorder(javax.swing.border.EmptyBorder)

Example 97 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class LogisticRegressionContent method createTablePortObject.

/**
 * Creates a BufferedDataTable with the
 * @param exec The execution context
 * @return a port object
 */
public BufferedDataTable createTablePortObject(final ExecutionContext exec) {
    DataTableSpec tableOutSpec = new DataTableSpec("Coefficients and Statistics", new String[] { "Logit", "Variable", "Coeff.", "Std. Err.", "z-score", "P>|z|" }, new DataType[] { StringCell.TYPE, StringCell.TYPE, DoubleCell.TYPE, DoubleCell.TYPE, DoubleCell.TYPE, DoubleCell.TYPE });
    BufferedDataContainer dc = exec.createDataContainer(tableOutSpec);
    List<DataCell> logits = this.getLogits();
    List<String> parameters = this.getParameters();
    int c = 0;
    for (DataCell logit : logits) {
        Map<String, Double> coefficients = this.getCoefficients(logit);
        Map<String, Double> stdErrs = this.getStandardErrors(logit);
        Map<String, Double> zScores = this.getZScores(logit);
        Map<String, Double> pValues = this.getPValues(logit);
        for (String parameter : parameters) {
            List<DataCell> cells = new ArrayList<DataCell>();
            cells.add(new StringCell(logit.toString()));
            cells.add(new StringCell(parameter));
            cells.add(new DoubleCell(coefficients.get(parameter)));
            cells.add(new DoubleCell(stdErrs.get(parameter)));
            cells.add(new DoubleCell(zScores.get(parameter)));
            cells.add(new DoubleCell(pValues.get(parameter)));
            c++;
            dc.addRowToTable(new DefaultRow("Row" + c, cells));
        }
        List<DataCell> cells = new ArrayList<DataCell>();
        cells.add(new StringCell(logit.toString()));
        cells.add(new StringCell("Constant"));
        cells.add(new DoubleCell(this.getIntercept(logit)));
        cells.add(new DoubleCell(this.getInterceptStdErr(logit)));
        cells.add(new DoubleCell(this.getInterceptZScore(logit)));
        cells.add(new DoubleCell(this.getInterceptPValue(logit)));
        c++;
        dc.addRowToTable(new DefaultRow("Row" + c, cells));
    }
    dc.close();
    return dc.getTable();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 98 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class LogisticRegressionContent method load.

/**
 * @param parContent the content that holds the internals
 * @param spec the data table spec of the training data
 * @return a instance with he loaded values
 * @throws InvalidSettingsException when data are not well formed
 */
static LogisticRegressionContent load(final ModelContentRO parContent, final DataTableSpec spec) throws InvalidSettingsException {
    String target = parContent.getString(CFG_TARGET);
    String[] learningCols = parContent.getStringArray(CFG_LEARNING_COLS);
    PMMLPortObjectSpec pmmlSpec = createSpec(spec, target, learningCols);
    String[] factors = parContent.getStringArray(CFG_FACTORS);
    String[] covariates = parContent.getStringArray(CFG_COVARIATES);
    double[] coeff = parContent.getDoubleArray(CFG_COEFFICIENTS);
    double likelihood = parContent.getDouble(CFG_LOG_LIKELIHOOD);
    double[] covMat = parContent.getDoubleArray(CFG_COVARIANCE_MATRIX);
    int iter = parContent.getInt(CFG_ITER);
    // introduced in 2.9
    DataCell targetReferenceCategory = parContent.getDataCell(CFG_TARGET_REFERENCE_CATEGORY, null);
    boolean sortTargetCategories = parContent.getBoolean(CFG_SORT_TARGET_CATEGORIES, true);
    boolean sortFactorsCategories = parContent.getBoolean(CFG_SORT_FACTORS_CATEGORIES, true);
    return new LogisticRegressionContent(pmmlSpec, Arrays.asList(factors), Arrays.asList(covariates), targetReferenceCategory, sortTargetCategories, sortFactorsCategories, toMatrix(coeff, coeff.length), likelihood, toMatrix(covMat, coeff.length), iter);
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataCell(org.knime.core.data.DataCell)

Example 99 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class LogisticRegressionContent method getValues.

private Map<String, Double> getValues(final DataCell logit, final RealMatrix matrix) {
    assert m_targetCategories.contains(logit);
    Map<String, Double> coefficients = new HashMap<String, Double>();
    int pCount = m_beta.getColumnDimension() / (m_targetCategories.size() - 1);
    int p = 1;
    for (String colName : m_outSpec.getLearningFields()) {
        if (m_factorList.contains(colName)) {
            Iterator<DataCell> designIter = m_factorDomainValues.get(colName).iterator();
            // Omit first
            designIter.next();
            while (designIter.hasNext()) {
                DataCell dvValue = designIter.next();
                String variable = colName + "=" + dvValue;
                int k = m_targetCategories.indexOf(logit);
                double coeff = matrix.getEntry(0, p + (k * pCount));
                coefficients.put(variable, coeff);
                p++;
            }
        } else {
            String variable = colName;
            int k = m_targetCategories.indexOf(logit);
            if (m_vectorLengths.containsKey(colName)) {
                int length = m_vectorLengths.get(colName).intValue();
                for (int i = 0; i < length; ++i) {
                    double coeff = matrix.getEntry(0, p + i + (k * pCount));
                    coefficients.put(VectorHandling.valueAt(variable, i), coeff);
                }
                p += length;
            } else {
                double coeff = matrix.getEntry(0, p + (k * pCount));
                coefficients.put(variable, coeff);
                p++;
            }
        }
    }
    return coefficients;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DataCell(org.knime.core.data.DataCell)

Example 100 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class LogisticRegressionContent method getParameters.

/**
 * Returns the parameters. The follow the notation rule:
 *   - for covariate (numeric learning column):
 *      "column_name"
 *   - for factors (nominal learning columns) there are n-1 entries
 *     when n is the number of domain values:
 *      "column_name=domain_value"
 * @return the parameters
 */
public List<String> getParameters() {
    List<String> parameters = new ArrayList<String>();
    for (String colName : m_outSpec.getLearningFields()) {
        if (m_factorList.contains(colName)) {
            Iterator<DataCell> designIter = m_factorDomainValues.get(colName).iterator();
            // Omit first
            designIter.next();
            while (designIter.hasNext()) {
                DataCell dvValue = designIter.next();
                String variable = colName + "=" + dvValue;
                parameters.add(variable);
            }
        } else {
            String variable = colName;
            if (m_vectorLengths.containsKey(colName)) {
                int length = m_vectorLengths.get(colName).intValue();
                for (int i = 0; i < length; ++i) {
                    parameters.add(VectorHandling.valueAt(variable, i));
                }
            } else {
                parameters.add(variable);
            }
        }
    }
    return parameters;
}
Also used : ArrayList(java.util.ArrayList) DataCell(org.knime.core.data.DataCell)

Aggregations

DataCell (org.knime.core.data.DataCell)780 DataRow (org.knime.core.data.DataRow)268 DataTableSpec (org.knime.core.data.DataTableSpec)175 DataColumnSpec (org.knime.core.data.DataColumnSpec)170 DefaultRow (org.knime.core.data.def.DefaultRow)169 ArrayList (java.util.ArrayList)141 StringCell (org.knime.core.data.def.StringCell)131 DoubleCell (org.knime.core.data.def.DoubleCell)129 DoubleValue (org.knime.core.data.DoubleValue)111 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)109 DataType (org.knime.core.data.DataType)97 RowKey (org.knime.core.data.RowKey)94 BufferedDataTable (org.knime.core.node.BufferedDataTable)93 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)91 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)84 LinkedHashMap (java.util.LinkedHashMap)81 IntCell (org.knime.core.data.def.IntCell)79 HashMap (java.util.HashMap)60 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)57 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)56