Search in sources :

Example 41 with DataColumnDomain

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

the class NominalTargetColumnHelper method createMetaData.

/**
 * {@inheritDoc}
 */
@Override
protected TreeTargetNominalColumnMetaData createMetaData(final DataColumnSpec nominalColSpec) {
    DataColumnDomain domain = nominalColSpec.getDomain();
    CheckUtils.checkArgument(domain.hasValues(), "The target field \"%s\" in the data dictionary has no possible values assigned.", nominalColSpec);
    NominalValueRepresentation[] nomVals = NominalColumnHelperUtil.extractNomValReps(domain.getValues());
    return new TreeTargetNominalColumnMetaData(nominalColSpec.getName(), nomVals);
}
Also used : DataColumnDomain(org.knime.core.data.DataColumnDomain) TreeTargetNominalColumnMetaData(org.knime.base.node.mine.treeensemble2.data.TreeTargetNominalColumnMetaData) NominalValueRepresentation(org.knime.base.node.mine.treeensemble2.data.NominalValueRepresentation)

Example 42 with DataColumnDomain

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

the class LogRegLearnerNodeDialogPane method updateTargetCategories.

/**
 * Update list of target categories.
 */
private void updateTargetCategories(final DataCell selectedItem) {
    m_targetReferenceCategory.removeAllItems();
    String selectedColumn = m_selectionPanel.getSelectedColumn();
    if (selectedColumn != null) {
        DataColumnSpec colSpec = m_inSpec.getColumnSpec(selectedColumn);
        if (null != colSpec) {
            // select last as default
            DataCell newSelectedItem = null;
            DataCell lastItem = null;
            final DataColumnDomain domain = colSpec.getDomain();
            if (domain.hasValues()) {
                for (DataCell cell : domain.getValues()) {
                    m_targetReferenceCategory.addItem(cell);
                    lastItem = cell;
                    if (cell.equals(selectedItem)) {
                        newSelectedItem = selectedItem;
                    }
                }
                if (newSelectedItem == null) {
                    newSelectedItem = lastItem;
                }
                m_targetReferenceCategory.getModel().setSelectedItem(newSelectedItem);
            }
        }
    }
    m_targetReferenceCategory.setEnabled(m_targetReferenceCategory.getModel().getSize() > 0);
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DataCell(org.knime.core.data.DataCell)

Example 43 with DataColumnDomain

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

the class LogRegLearnerNodeDialogPane method updateTargetCategories.

/**
 * Update list of target categories.
 */
private void updateTargetCategories(final DataCell selectedItem) {
    m_targetReferenceCategory.removeAllItems();
    String selectedColumn = m_selectionPanel.getSelectedColumn();
    if (selectedColumn != null) {
        DataColumnSpec colSpec = m_inSpec.getColumnSpec(selectedColumn);
        if (null != colSpec) {
            // select last as default
            DataCell newSelectedItem = null;
            DataCell lastItem = null;
            final DataColumnDomain domain = colSpec.getDomain();
            if (domain.hasValues()) {
                for (DataCell cell : domain.getValues()) {
                    m_targetReferenceCategory.addItem(cell);
                    lastItem = cell;
                    if (cell.equals(selectedItem)) {
                        newSelectedItem = selectedItem;
                    }
                }
                if (newSelectedItem == null) {
                    newSelectedItem = lastItem;
                }
                m_targetReferenceCategory.getModel().setSelectedItem(newSelectedItem);
            }
        }
    }
    m_targetReferenceCategory.setEnabled(m_targetReferenceCategory.getModel().getSize() > 0);
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DataCell(org.knime.core.data.DataCell)

Example 44 with DataColumnDomain

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

the class LogRegLearner method checkConstantLearningFields.

private void checkConstantLearningFields(final BufferedDataTable data) throws InvalidSettingsException {
    Set<String> exclude = new HashSet<String>();
    for (DataColumnSpec colSpec : m_pmmlOutSpec.getLearningCols()) {
        if (colSpec.getType().isCompatible(DoubleValue.class)) {
            final DataColumnDomain domain = colSpec.getDomain();
            final DataCell lowerBound = domain.getLowerBound();
            final DataCell upperBound = domain.getUpperBound();
            assert lowerBound != null || data.size() == 0 : "Non empty table must have domain set at this point";
            if (ObjectUtils.equals(lowerBound, upperBound)) {
                exclude.add(colSpec.getName());
            }
        }
    }
    // Maybe in recalcDomainForTargetAndLearningFields.
    if (!exclude.isEmpty()) {
        StringBuilder warning = new StringBuilder();
        warning.append(exclude.size() == 1 ? "Column " : "Columns ");
        warning.append(ConvenienceMethods.getShortStringFrom(exclude, 5));
        warning.append(exclude.size() == 1 ? " has a constant value " : " have constant values ");
        warning.append(" - will be ignored during training");
        LOGGER.warn(warning.toString());
        m_warningMessage = (m_warningMessage == null ? "" : m_warningMessage + "\n") + warning.toString();
        // re-init learner so that it has the correct learning columns
        init(data.getDataTableSpec(), exclude);
    }
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DataCell(org.knime.core.data.DataCell) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 45 with DataColumnDomain

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

the class DoubleGrayValueRenderer method setValue.

/**
 *    /** Sets the gray value according to the value and the column
 * domain's min/max. If the object is not instance of DoubleValue, the
 * cell is painted red.
 * @param value The value to be rendered.
 * @see javax.swing.table.DefaultTableCellRenderer#setValue(Object)
 */
@Override
protected void setValue(final Object value) {
    Color c;
    if (value instanceof DoubleValue) {
        DoubleValue cell = (DoubleValue) value;
        double val = cell.getDoubleValue();
        DataColumnSpec spec = getColSpec();
        double min = Double.POSITIVE_INFINITY;
        double max = Double.NEGATIVE_INFINITY;
        if (spec != null) {
            DataColumnDomain domain = spec.getDomain();
            DataCell lower = domain.getLowerBound();
            DataCell upper = domain.getUpperBound();
            if (lower instanceof DoubleValue) {
                min = ((DoubleValue) lower).getDoubleValue();
            }
            if (upper instanceof DoubleValue) {
                max = ((DoubleValue) upper).getDoubleValue();
            }
        }
        if (min >= max) {
            min = 0.0;
            max = 1.0;
        }
        setToolTipText(Double.toString(val));
        c = setDoubleValue(val, min, max);
        setIconColor(c);
        setTextInternal(null);
    } else if (isPaintCrossForMissing()) {
        setToolTipText("Missing Value");
        setIconColor(null);
        setTextInternal(null);
    } else {
        setToolTipText("Missing Value");
        setIcon(null);
        setTextInternal(DataType.getMissingCell().toString());
    }
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DoubleValue(org.knime.core.data.DoubleValue) Color(java.awt.Color) DataCell(org.knime.core.data.DataCell)

Aggregations

DataColumnDomain (org.knime.core.data.DataColumnDomain)46 DataColumnSpec (org.knime.core.data.DataColumnSpec)34 DataCell (org.knime.core.data.DataCell)32 DataTableSpec (org.knime.core.data.DataTableSpec)20 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)16 DoubleValue (org.knime.core.data.DoubleValue)13 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)12 DataType (org.knime.core.data.DataType)11 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)8 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)7 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)5 DoubleCell (org.knime.core.data.def.DoubleCell)5 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedList (java.util.LinkedList)3 Set (java.util.Set)3 DataRow (org.knime.core.data.DataRow)3