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);
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations