use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class AbstractNormalizerPMMLNodeModel method prepareConfigure.
/**
* @param inSpecs An array of DataTableSpecs (as many as this model has
* inputs).
* @return An array of DataTableSpecs (as many as this model has outputs)
*
* @throws InvalidSettingsException if the <code>#configure()</code> failed,
* that is, the settings are inconsistent with given
* DataTableSpec elements.
*/
@Override
protected PortObjectSpec[] prepareConfigure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec spec = (DataTableSpec) inSpecs[0];
PMMLPortObjectSpecCreator pmmlSpecCreator;
if (m_hasModelIn) {
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
// extract selected numeric columns
updateNumericColumnSelection(spec);
if (getMode() == NONORM_MODE) {
return new PortObjectSpec[] { spec, pmmlSpec };
}
pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, spec);
} else {
// extract selected numeric columns
updateNumericColumnSelection(spec);
if (getMode() == NONORM_MODE) {
return new PortObjectSpec[] { spec };
}
pmmlSpecCreator = new PMMLPortObjectSpecCreator(spec);
}
return new PortObjectSpec[] { Normalizer2.generateNewSpec(spec, getColumns()), pmmlSpecCreator.createSpec() };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class AbstractNormalizerPMMLNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
CalculationResult result = calculate(inObjects, exec);
BufferedDataTable outTable = result.getDataTable();
// the optional PMML in port (can be null)
PMMLPortObject inPMMLPort = m_hasModelIn ? (PMMLPortObject) inObjects[1] : null;
PMMLNormalizeTranslator trans = new PMMLNormalizeTranslator(result.getConfig(), new DerivedFieldMapper(inPMMLPort));
DataTableSpec dataTableSpec = (DataTableSpec) inObjects[0].getSpec();
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, dataTableSpec);
PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
return new PortObject[] { outTable, outPMMLPort };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class CategoryToNumberNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
List<String> inputCols = new ArrayList<String>();
for (DataColumnSpec column : inSpec) {
if (column.getType().isCompatible(StringValue.class)) {
inputCols.add(column.getName());
}
}
FilterResult filter = m_settings.getFilterConfiguration().applyTo(inSpec);
String[] rmFromIncl = filter.getRemovedFromIncludes();
if (m_settings.getFilterConfiguration().isEnforceInclusion() && rmFromIncl.length != 0) {
throw new InvalidSettingsException("Input table does not contain the following selected column(s): " + ConvenienceMethods.getShortStringFrom(new HashSet<String>(Arrays.asList(rmFromIncl)), 3));
}
m_included = filter.getIncludes();
if (m_included.length == 0) {
setWarningMessage("No columns selected.");
}
ColumnRearranger rearranger = createRearranger(inSpec);
PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inSpec);
pmmlSpecCreator.addPreprocColNames(inputCols);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class LinearRegressionContent method createPortObjectSpec.
/**
* Creates a PMML port object spec based on all columns in the given data
* table spec. <b>The target column must be the last column in the table
* spec!</b>
*
* @param pmmlSpec the optional {@link PMMLPortObjectSpec} which can be null
* @param tableSpec the full data table spec with which the regression
* model was created.
* @param learningSpec a data table spec containing only columns used for
* learning the model
* @return a PMML port object spec
* @throws InvalidSettingsException if PMML incompatible type was found
*/
public static PMMLPortObjectSpec createPortObjectSpec(final PMMLPortObjectSpec pmmlSpec, final DataTableSpec tableSpec, final DataTableSpec learningSpec) throws InvalidSettingsException {
PMMLPortObjectSpecCreator c = new PMMLPortObjectSpecCreator(pmmlSpec, tableSpec);
int numColumns = learningSpec.getNumColumns();
String[] learningCols = new String[numColumns - 1];
for (int i = 0; i < learningCols.length; i++) {
learningCols[i] = learningSpec.getColumnSpec(i).getName();
}
c.setLearningCols(FilterColumnTable.createFilterTableSpec(learningSpec, learningCols));
c.setTargetCols(Arrays.asList(learningSpec.getColumnSpec(numColumns - 1)));
return c.createSpec();
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class GBTPMMLExporterNodeModel method createPMMLSpec.
private PMMLPortObjectSpec createPMMLSpec(final TreeEnsembleModelPortObjectSpec spec, final AbstractGradientBoostingModel model) {
DataColumnSpec targetSpec = spec.getTargetColumn();
DataTableSpec learnFeatureSpec = spec.getLearnTableSpec();
if (containsVector(learnFeatureSpec)) {
setWarningMessage("The model was learned on a vector column. It's possible to export the model " + "to PMML but it won't be possible to import it from the exported PMML.");
}
if (model == null && containsVector(learnFeatureSpec)) {
// at this point we don't know how long the vector column is
return null;
} else if (model != null) {
// possibly expand vectors with model
learnFeatureSpec = model.getLearnAttributeSpec(learnFeatureSpec);
}
DataTableSpec completeLearnSpec = new DataTableSpec(learnFeatureSpec, new DataTableSpec(targetSpec));
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(completeLearnSpec);
try {
pmmlSpecCreator.setLearningCols(learnFeatureSpec);
} catch (InvalidSettingsException e) {
// (as of KNIME v2.5.1)
throw new IllegalStateException(e);
}
pmmlSpecCreator.setTargetCol(targetSpec);
return pmmlSpecCreator.createSpec();
}
Aggregations