use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class PMMLRegressionTranslator method exportTo.
/**
* {@inheritDoc}
*/
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
m_nameMapper = new DerivedFieldMapper(pmmlDoc);
RegressionModel regressionModel = pmmlDoc.getPMML().addNewRegressionModel();
regressionModel.setFunctionName(MININGFUNCTION.REGRESSION);
if (m_algorithmName != null && !m_algorithmName.isEmpty()) {
regressionModel.setAlgorithmName(m_algorithmName);
}
regressionModel.setModelName(m_modelName);
regressionModel.setTargetFieldName(m_targetField);
PMMLMiningSchemaTranslator.writeMiningSchema(spec, regressionModel);
RegressionTableDocument.RegressionTable regressionTable = regressionModel.addNewRegressionTable();
regressionTable.setIntercept(m_regressionTable.getIntercept());
for (NumericPredictor p : m_regressionTable.getVariables()) {
NumericPredictorDocument.NumericPredictor np = regressionTable.addNewNumericPredictor();
np.setName(m_nameMapper.getDerivedFieldName(p.getName()));
if (p.getExponent() != 1) {
np.setExponent(BigInteger.valueOf(p.getExponent()));
}
np.setCoefficient(p.getCoefficient());
}
return RegressionModel.type;
}
use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper 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.preproc.DerivedFieldMapper 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.preproc.DerivedFieldMapper 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 };
}
}
use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class MissingCellReplacingDataTable method prepareHandlers.
/**
* @param inTableSpec
* @param pmmlDoc
* @return
* @throws InvalidSettingsException
*/
private MissingCellHandler[] prepareHandlers(final DataTableSpec inTableSpec, final PMMLDocument pmmlDoc) throws InvalidSettingsException {
MissingCellHandler[] handlers = new MissingCellHandler[inTableSpec.getNumColumns()];
if (pmmlDoc.getPMML().getTransformationDictionary() == null || pmmlDoc.getPMML().getTransformationDictionary().getDerivedFieldList().size() == 0) {
for (int i = 0; i < inTableSpec.getNumColumns(); i++) {
handlers[i] = DoNothingMissingCellHandlerFactory.getInstance().createHandler(inTableSpec.getColumnSpec(i));
}
return handlers;
}
DerivedFieldMapper mapper = new DerivedFieldMapper(pmmlDoc);
Map<String, DerivedField> derivedFields = new HashMap<>();
for (DerivedField df : pmmlDoc.getPMML().getTransformationDictionary().getDerivedFieldList()) {
String name = mapper.getColumnName(df.getName());
derivedFields.put(name, df);
}
for (int i = 0; i < inTableSpec.getNumColumns(); i++) {
DataColumnSpec spec = inTableSpec.getColumnSpec(i);
handlers[i] = createHandlerForColumn(spec, derivedFields.get(spec.getName()));
}
return handlers;
}
Aggregations