Search in sources :

Example 11 with DataColumnDomain

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

the class LogRegCoordinator 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 (java.util.Objects.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_warning = (m_warning == null ? "" : m_warning + "\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 12 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 13 with DataColumnDomain

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

the class AbstractHistogramVizModel method calculateMaxNoOfBins.

/**
 * Calculates the maximum number of bins which could be displayed.
 */
private void calculateMaxNoOfBins() {
    // handle nominal binning special
    if (isBinNominal()) {
        final DataColumnSpec xColSpec = getXColumnSpec();
        final DataColumnDomain domain = xColSpec.getDomain();
        if (domain == null) {
            throw new IllegalStateException("Binning column domain must not be null");
        }
        final Set<DataCell> values = domain.getValues();
        if (values == null) {
            throw new IllegalStateException("Values of binning column domain must not be null");
        }
        m_maxNoOfBins = values.size();
        return;
    }
    // handle integer values special
    final DataColumnSpec xColSpec = getXColumnSpec();
    int maxNoOfBins = BinningUtil.calculateIntegerMaxNoOfBins(Integer.MAX_VALUE, xColSpec);
    // avoid rounding errors and display at least one bar
    if (maxNoOfBins < 1) {
        maxNoOfBins = 1;
    }
    m_maxNoOfBins = maxNoOfBins;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) DataCell(org.knime.core.data.DataCell) Point(java.awt.Point)

Example 14 with DataColumnDomain

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

the class BinningUtil method checkDomainRange.

/**
 * Checks if the given cell is in the domain range of the given
 * {@link DataColumnSpec}. If the cell is missing the method returns
 * <code>true</code>.
 * @param cell the cell to check
 * @param spec the {@link DataColumnSpec} with the domain
 * @return <code>true</code> if the cell is missing or the value is between
 * the upper and lower bound specified by the domain of the given column
 * specification
 */
public static boolean checkDomainRange(final DataCell cell, final DataColumnSpec spec) {
    if (!cell.isMissing()) {
        if (!cell.getType().isCompatible(DoubleValue.class)) {
            throw new IllegalStateException("X value is not a valid number");
        }
        final DataColumnDomain domain = spec.getDomain();
        final DataCell lowerBoundCell = domain.getLowerBound();
        if (lowerBoundCell == null || lowerBoundCell.isMissing() || !lowerBoundCell.getType().isCompatible(DoubleValue.class)) {
            throw new IllegalArgumentException("The lower bound of the binning column domain " + "should be defined");
        }
        final double lowerBound = ((DoubleValue) lowerBoundCell).getDoubleValue();
        final DataCell upperBoundCell = domain.getUpperBound();
        if (upperBoundCell == null || upperBoundCell.isMissing() || !upperBoundCell.getType().isCompatible(DoubleValue.class)) {
            throw new IllegalArgumentException("The upper bound of the binning column domain " + "should be defined");
        }
        final double upperBound = ((DoubleValue) upperBoundCell).getDoubleValue();
        if (((DoubleValue) cell).getDoubleValue() < lowerBound || ((DoubleValue) cell).getDoubleValue() > upperBound) {
            return false;
        }
    }
    return true;
}
Also used : DataColumnDomain(org.knime.core.data.DataColumnDomain) DoubleValue(org.knime.core.data.DoubleValue) DataCell(org.knime.core.data.DataCell)

Example 15 with DataColumnDomain

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

the class BinningUtil method binNominal.

/**
 * @param colSpec the {@link DataColumnSpec} of the column to bin
 * @param noOfBins the number of bins
 * @return <code>true</code> if the bins should be nominal
 */
public static boolean binNominal(final DataColumnSpec colSpec, final int noOfBins) {
    final DataType dataType = colSpec.getType();
    if (!dataType.isCompatible(DoubleValue.class)) {
        // it's not numerical
        return true;
    }
    if (dataType.isCompatible(LongValue.class)) {
        // it's an integer...
        final DataColumnDomain domain = colSpec.getDomain();
        final long lowerBound = ((LongValue) domain.getLowerBound()).getLongValue();
        final long upperBound = ((LongValue) domain.getUpperBound()).getLongValue();
        if (upperBound - lowerBound <= noOfBins) {
            // an own bin
            return true;
        }
    }
    return false;
}
Also used : DataColumnDomain(org.knime.core.data.DataColumnDomain) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataType(org.knime.core.data.DataType)

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