use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class MLPPredictorNodeModel method configure.
/**
* The additional columns are created based on the model which is loaded in
* the execute-method. Therefore, new DataTableSpecs are not available until
* execute has been called.
*
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
PMMLPortObjectSpec modelspec = (PMMLPortObjectSpec) inSpecs[0];
DataTableSpec testSpec = (DataTableSpec) inSpecs[1];
List<DataColumnSpec> targetCols = modelspec.getTargetCols();
if (targetCols.isEmpty()) {
throw new InvalidSettingsException("The PMML model" + " does not specify a target column for the prediction.");
}
DataColumnSpec targetCol = targetCols.iterator().next();
/*
* Check consistency between model and inputs, find columns to work on.
*/
for (String incol : modelspec.getLearningFields()) {
if (!testSpec.containsName(incol)) {
throw new InvalidSettingsException("Could not find " + incol + " in inputspec");
}
}
m_columns = getLearningColumnIndices(testSpec, modelspec);
final String prediction = PredictorHelper.getInstance().checkedComputePredictionColumnName(m_predictionColumn.getStringValue(), m_overridePrediction.getBooleanValue(), targetCol.getName());
MLPClassificationFactory mymlp;
// Regression
if (targetCol.getType().isCompatible(DoubleValue.class)) {
mymlp = new MLPClassificationFactory(true, m_columns, targetCol, prediction, m_appendProbs.getBooleanValue(), m_suffix.getStringValue());
} else {
// Classification
mymlp = new MLPClassificationFactory(false, m_columns, targetCol, prediction, m_appendProbs.getBooleanValue(), m_suffix.getStringValue());
}
ColumnRearranger colre = new ColumnRearranger(testSpec);
colre.append(mymlp);
return new DataTableSpec[] { colre.createSpec() };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class DataColumnSpecFilterPMMLNodeModel method configure.
/**
* Excludes a number of columns from the input spec and generates a new output spec.
*
* @param inSpecs the input table spec
* @return outSpecs the output table spec with some excluded columns
*
* @throws InvalidSettingsException if the selected column is not available
* in the table spec.
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
final DataTableSpec outSpec = super.configure(new DataTableSpec[] { inSpec })[0];
final FilterResult res = getFilterResult(inSpec);
final PMMLPortObjectSpec pmmlSpec = createPMMLSpec((PMMLPortObjectSpec) inSpecs[1], inSpec, res);
return new PortObjectSpec[] { outSpec, pmmlSpec };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class BinnerNodeModel method configure.
/**
* Passes the input spec to the output.
*
* @param inSpecs The input spec.
* @return The generated output specs.
* @throws InvalidSettingsException If column to bin cannot be identified.
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inDataSpec = (DataTableSpec) inSpecs[DATA_INPORT];
PMMLPortObjectSpec inModelSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[MODEL_INPORT] : null;
for (String columnKey : m_columnToBins.keySet()) {
assert m_columnToAppended.containsKey(columnKey) : columnKey;
if (!inDataSpec.containsName(columnKey)) {
throw new InvalidSettingsException("Binner: column \"" + columnKey + "\" not found in spec.");
}
if (!inDataSpec.getColumnSpec(columnKey).getType().isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("Binner: column \"" + columnKey + "\" not compatible with double-type.");
}
String appended = m_columnToAppended.get(columnKey);
if (appended != null) {
if (inDataSpec.containsName(appended)) {
throw new InvalidSettingsException("Binner: duplicate " + "appended column \"" + appended + "\" in spec.");
}
}
}
// set warning when no binning is defined
if (m_columnToBins.isEmpty()) {
super.setWarningMessage("No column select for binning.");
}
// generate numeric binned table spec
DataTableSpec outDataSpec = createColumnRearranger(inDataSpec).createSpec();
if (!m_pmmlOutEnabled) {
return new PortObjectSpec[] { outDataSpec };
}
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(inModelSpec, outDataSpec);
return new PortObjectSpec[] { outDataSpec, pmmlSpecCreator.createSpec() };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class Many2OneCol2PMMLNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inDataSpec = (DataTableSpec) inSpecs[0];
String[] includes = m_includedColumns.applyTo(inDataSpec).getIncludes();
if (includes.length <= 0) {
setWarningMessage("No column selected. Node will have no effect!");
}
// if it is not a reg exp it must be double compatible
if (!m_includeMethod.getStringValue().equals(IncludeMethod.RegExpPattern.name())) {
for (String colName : includes) {
if (!inDataSpec.getColumnSpec(colName).getType().isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("For selected include method '" + m_includeMethod.getStringValue() + "' only double compatible values are allowed." + " Column '" + colName + "' is not.");
}
}
}
ColumnRearranger rearranger = createRearranger(inDataSpec, getCellFactory(inDataSpec));
if (m_pmmlOutEnabled) {
PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inDataSpec);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
} else {
return new DataTableSpec[] { rearranger.createSpec() };
}
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpec in project knime-core by knime.
the class StringToNumberNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
// find indices to work on
DataTableSpec dts = (DataTableSpec) inSpecs[0];
int[] indices = findColumnIndices(dts);
ConverterFactory converterFac = new ConverterFactory(indices, dts, m_parseType);
ColumnRearranger colre = new ColumnRearranger(dts);
colre.replace(converterFac, indices);
DataTableSpec newspec = colre.createSpec();
// create the PMML spec based on the optional incoming PMML spec
PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, dts);
return new PortObjectSpec[] { newspec, pmmlSpecCreator.createSpec() };
}
Aggregations