use of org.knime.core.data.DataTableDomainCreator in project knime-core by knime.
the class DomainNodeModel method getDomainCreator.
private DataTableDomainCreator getDomainCreator(final DataTableSpec inputSpec) {
final Set<String> possValCols = new HashSet<String>();
possValCols.addAll(Arrays.asList(m_possValCols));
int maxPoss = m_maxPossValues >= 0 ? m_maxPossValues : Integer.MAX_VALUE;
final Set<String> minMaxCols = new HashSet<String>();
minMaxCols.addAll(Arrays.asList(m_minMaxCols));
DomainCreatorColumnSelection possValueSelection = new DomainCreatorColumnSelection() {
@Override
public boolean createDomain(final DataColumnSpec colSpec) {
return possValCols.contains(colSpec.getName());
}
@Override
public boolean dropDomain(final DataColumnSpec colSpec) {
return possValCols.contains(colSpec.getName()) || !m_possValRetainUnselected;
}
};
DomainCreatorColumnSelection minMaxSelection = new DomainCreatorColumnSelection() {
@Override
public boolean createDomain(final DataColumnSpec colSpec) {
return minMaxCols.contains(colSpec.getName());
}
@Override
public boolean dropDomain(final DataColumnSpec colSpec) {
return minMaxCols.contains(colSpec.getName()) || !m_minMaxRetainUnselected;
}
};
DataTableDomainCreator domainCreator = new DataTableDomainCreator(inputSpec, possValueSelection, minMaxSelection);
domainCreator.setMaxPossibleValues(maxPoss);
return domainCreator;
}
use of org.knime.core.data.DataTableDomainCreator in project knime-core by knime.
the class DomainNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
DataTableDomainCreator domainCreator = getDomainCreator(inData[0].getDataTableSpec());
domainCreator.updateDomain(inData[0], exec, inData[0].getRowCount());
return new BufferedDataTable[] { exec.createSpecReplacerTable(inData[0], domainCreator.createSpec()) };
}
use of org.knime.core.data.DataTableDomainCreator in project knime-core by knime.
the class LogRegCoordinator method recalcDomainForTargetAndLearningFields.
private BufferedDataTable recalcDomainForTargetAndLearningFields(final BufferedDataTable data, final ExecutionContext exec) throws InvalidSettingsException, CanceledExecutionException {
final String targetCol = m_pmmlOutSpec.getTargetFields().get(0);
DataTableDomainCreator domainCreator = new DataTableDomainCreator(data.getDataTableSpec(), new DomainCreatorColumnSelection() {
@Override
public boolean dropDomain(final DataColumnSpec colSpec) {
return false;
}
@Override
public boolean createDomain(final DataColumnSpec colSpec) {
return colSpec.getName().equals(targetCol) || (colSpec.getType().isCompatible(NominalValue.class) && m_pmmlOutSpec.getLearningFields().contains(colSpec.getName()));
}
}, new DomainCreatorColumnSelection() {
@Override
public boolean dropDomain(final DataColumnSpec colSpec) {
// drop domain of numeric learning fields so that we can check for constant columns
return colSpec.getType().isCompatible(DoubleValue.class) && m_pmmlOutSpec.getLearningFields().contains(colSpec.getName());
}
@Override
public boolean createDomain(final DataColumnSpec colSpec) {
return colSpec.getType().isCompatible(DoubleValue.class) && m_pmmlOutSpec.getLearningFields().contains(colSpec.getName());
}
});
domainCreator.updateDomain(data, exec);
DataTableSpec spec = domainCreator.createSpec();
CheckUtils.checkSetting(spec.getColumnSpec(targetCol).getDomain().hasValues(), "Target column '%s' has too many" + " unique values - consider to use domain calucator node before to enforce calculation", targetCol);
BufferedDataTable newDataTable = exec.createSpecReplacerTable(data, spec);
// bug fix 5580 - ignore columns with too many different values
Set<String> columnWithTooManyDomainValues = new LinkedHashSet<>();
for (String learningField : m_pmmlOutSpec.getLearningFields()) {
DataColumnSpec columnSpec = spec.getColumnSpec(learningField);
if (columnSpec.getType().isCompatible(NominalValue.class) && !columnSpec.getDomain().hasValues()) {
columnWithTooManyDomainValues.add(learningField);
}
}
if (!columnWithTooManyDomainValues.isEmpty()) {
StringBuilder warning = new StringBuilder();
warning.append(columnWithTooManyDomainValues.size() == 1 ? "Column " : "Columns ");
warning.append(ConvenienceMethods.getShortStringFrom(columnWithTooManyDomainValues, 5));
warning.append(columnWithTooManyDomainValues.size() == 1 ? " has " : " have ");
warning.append("too many different values - will be ignored during training ");
warning.append("(enforce inclusion by using a domain calculator node before)");
// LOGGER.warn(warning.toString());
m_warning = (m_warning == null ? "" : m_warning + "\n") + warning.toString();
}
// initialize m_learner so that it has the correct DataTableSpec of the input
init(newDataTable.getDataTableSpec(), columnWithTooManyDomainValues);
return newDataTable;
}
use of org.knime.core.data.DataTableDomainCreator in project knime-core by knime.
the class LinReg2Learner method recalcDomainOfLearningFields.
private BufferedDataTable recalcDomainOfLearningFields(final BufferedDataTable data, final PMMLPortObjectSpec inPMMLSpec, final ExecutionContext exec) throws InvalidSettingsException, CanceledExecutionException {
DataTableDomainCreator domainCreator = new DataTableDomainCreator(data.getDataTableSpec(), new DomainCreatorColumnSelection() {
@Override
public boolean dropDomain(final DataColumnSpec colSpec) {
return true;
}
@Override
public boolean createDomain(final DataColumnSpec colSpec) {
return colSpec.getType().isCompatible(NominalValue.class) && (m_pmmlOutSpec.getLearningFields().contains(colSpec.getName()) || m_pmmlOutSpec.getTargetFields().contains(colSpec.getName()));
}
}, new DomainCreatorColumnSelection() {
@Override
public boolean dropDomain(final DataColumnSpec colSpec) {
return false;
}
@Override
public boolean createDomain(final DataColumnSpec colSpec) {
return false;
}
});
domainCreator.updateDomain(data, exec);
DataTableSpec spec = domainCreator.createSpec();
BufferedDataTable newDataTable = exec.createSpecReplacerTable(data, spec);
// bug fix 5793, similar to 5580 in LogReg2Learner - ignore columns with too many different values.
// But because this would change behavior, we cannot drop the domain, which means that even
// prepending a domain calculator to this node will node help when the column has too many values.
Set<String> columnWithTooManyDomainValues = new LinkedHashSet<>();
for (String learningField : m_pmmlOutSpec.getLearningFields()) {
DataColumnSpec columnSpec = spec.getColumnSpec(learningField);
if (columnSpec.getType().isCompatible(NominalValue.class) && !columnSpec.getDomain().hasValues()) {
columnWithTooManyDomainValues.add(learningField);
}
}
// initialize m_learner so that it has the correct DataTableSpec of
// the input
init(newDataTable.getDataTableSpec(), inPMMLSpec, columnWithTooManyDomainValues);
if (!columnWithTooManyDomainValues.isEmpty()) {
StringBuilder warning = new StringBuilder();
warning.append(columnWithTooManyDomainValues.size() == 1 ? "Column " : "Columns ");
warning.append(ConvenienceMethods.getShortStringFrom(columnWithTooManyDomainValues, 5));
warning.append(columnWithTooManyDomainValues.size() == 1 ? " has " : " have ");
warning.append("too many different values - will be ignored during training");
// warning.append("(enforce inclusion by using a domain calculator node before)");
LOGGER.warn(warning.toString());
m_warningMessage = (m_warningMessage == null ? "" : m_warningMessage + "\n") + warning.toString();
}
return newDataTable;
}
use of org.knime.core.data.DataTableDomainCreator in project knime-core by knime.
the class DomainNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
// auto-configuration in case no user settings are available
DataTableSpec spec = inSpecs[0];
if (m_possValConfig == null) {
m_possValConfig = createDCSFilterConfigurationPossVals();
m_possValConfig.loadDefaults(DomainNodeModel.getAllCols(NominalValue.class, spec), null, EnforceOption.EnforceInclusion);
}
if (m_minMaxConfig == null) {
m_minMaxConfig = createDCSFilterConfigurationMinMax();
m_minMaxConfig.loadDefaults(DomainNodeModel.getAllCols(BoundedValue.class, spec), null, EnforceOption.EnforceInclusion);
}
FilterResult filter = m_possValConfig.applyTo(spec);
String[] rmFromIncl = filter.getRemovedFromIncludes();
if (m_possValConfig.isEnforceInclusion() && rmFromIncl.length != 0) {
throw new InvalidSettingsException("Input table does not contain the following column(s) selected in the " + "possible value panel: " + ConvenienceMethods.getShortStringFrom(new HashSet<String>(Arrays.asList(rmFromIncl)), 3));
}
filter = m_minMaxConfig.applyTo(spec);
rmFromIncl = filter.getRemovedFromIncludes();
if (m_possValConfig.isEnforceInclusion() && rmFromIncl.length != 0) {
throw new InvalidSettingsException("Input table does not contain the following column(s) selected in the " + "Min/Max value panel: " + ConvenienceMethods.getShortStringFrom(new HashSet<String>(Arrays.asList(rmFromIncl)), 3));
}
DataTableDomainCreator domainCreator = getDomainCreator(spec);
return new DataTableSpec[] { domainCreator.createSpec() };
}
Aggregations