use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class DecisionTreeLearnerNodeModel2 method createPMMLPortObjectSpec.
private PMMLPortObjectSpec createPMMLPortObjectSpec(final PMMLPortObjectSpec modelSpec, final DataTableSpec spec) {
String targetCol = m_classifyColumn.getStringValue();
List<String> learnCols = new LinkedList<String>();
for (int i = 0; i < spec.getNumColumns(); i++) {
DataColumnSpec columnSpec = spec.getColumnSpec(i);
String col = columnSpec.getName();
if (!col.equals(targetCol) && (columnSpec.getType().isCompatible(DoubleValue.class) || columnSpec.getType().isCompatible(NominalValue.class) && (!m_skipColumns.getBooleanValue() || columnSpec.getDomain().hasValues()))) {
learnCols.add(spec.getColumnSpec(i).getName());
}
}
String[] usedCols = learnCols.toArray(new String[learnCols.size() + 1]);
usedCols[usedCols.length - 1] = targetCol;
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(modelSpec, spec);
pmmlSpecCreator.setLearningColsNames(learnCols);
pmmlSpecCreator.setTargetColName(targetCol);
return pmmlSpecCreator.createSpec();
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class CategoryToNumberNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
BufferedDataTable inData = (BufferedDataTable) inObjects[0];
DataTableSpec inSpec = (DataTableSpec) inObjects[0].getSpec();
ColumnRearranger rearranger = createRearranger(inSpec);
BufferedDataTable outTable = exec.createColumnRearrangeTable(inData, rearranger, exec);
// the optional PMML in port (can be null)
PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, rearranger.createSpec());
PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
for (CategoryToNumberCellFactory factory : m_factories) {
PMMLMapValuesTranslator trans = new PMMLMapValuesTranslator(factory.getConfig(), new DerivedFieldMapper(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 createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
ColumnRearranger cr = createRearranger((DataTableSpec) inSpecs[0]);
cr.createStreamableFunction(0, 0).runFinal(inputs, outputs, exec);
// the optional PMML in port (can be null)
PMMLPortObject inPMMLPort = null;
if (m_pmmlInEnabled && inputs[1] != null) {
inPMMLPort = (PMMLPortObject) ((PortObjectInput) inputs[1]).getPortObject();
}
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, cr.createSpec());
PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
for (CategoryToNumberCellFactory factory : m_factories) {
PMMLMapValuesTranslator trans = new PMMLMapValuesTranslator(factory.getConfig(), new DerivedFieldMapper(inPMMLPort));
outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
}
PortObjectOutput portObjectOutput = (PortObjectOutput) outputs[1];
portObjectOutput.setPortObject(outPMMLPort);
}
};
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class DataColumnSpecFilterPMMLNodeModel method createPMMLSpec.
private PMMLPortObjectSpec createPMMLSpec(final PMMLPortObjectSpec pmmlIn, final DataTableSpec spec, final FilterResult res) {
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(pmmlIn, spec);
if (pmmlIn != null) {
List<String> learningCols = new ArrayList<String>();
for (DataColumnSpec s : pmmlIn.getLearningCols()) {
if (!isExcluded(s.getName(), res)) {
learningCols.add(s.getName());
}
}
creator.setLearningColsNames(learningCols);
List<String> targetCols = new ArrayList<String>();
for (DataColumnSpec s : pmmlIn.getTargetCols()) {
if (!isExcluded(s.getName(), res)) {
targetCols.add(s.getName());
}
}
creator.setTargetColsNames(targetCols);
List<String> preprocCols = new ArrayList<String>();
for (DataColumnSpec s : pmmlIn.getPreprocessingCols()) {
if (!isExcluded(s.getName(), res)) {
preprocCols.add(s.getName());
}
}
creator.setPreprocColNames(preprocCols);
}
return creator.createSpec();
}
use of org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator in project knime-core by knime.
the class One2ManyCol2PMMLNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
BufferedDataTable inData = (BufferedDataTable) inObjects[0];
DataTableSpec dts = inData.getDataTableSpec();
checkColumnsSpecs(dts);
String[] includes = m_includedColumns.applyTo(dts).getIncludes();
One2ManyCellFactory cellFactory = new One2ManyCellFactory(dts, Arrays.asList(includes), m_appendOrgColName);
BufferedDataTable outData = exec.createColumnRearrangeTable(inData, createRearranger(dts, cellFactory), exec);
if (m_pmmlOutEnabled) {
// the optional PMML in port (can be null)
PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
PMMLOne2ManyTranslator trans = new PMMLOne2ManyTranslator(cellFactory.getColumnMapping(), new DerivedFieldMapper(inPMMLPort));
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, outData.getDataTableSpec());
PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
return new PortObject[] { outData, outPMMLPort };
} else {
return new PortObject[] { outData };
}
}
Aggregations