Search in sources :

Example 11 with DerivedFieldMapper

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;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) RegressionTableDocument(org.dmg.pmml.RegressionTableDocument) NumericPredictorDocument(org.dmg.pmml.NumericPredictorDocument) RegressionModel(org.dmg.pmml.RegressionModelDocument.RegressionModel)

Example 12 with DerivedFieldMapper

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 };
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 13 with DerivedFieldMapper

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);
        }
    };
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) PortObjectInput(org.knime.core.node.streamable.PortObjectInput) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator) PortObjectOutput(org.knime.core.node.streamable.PortObjectOutput)

Example 14 with DerivedFieldMapper

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 };
    }
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) One2ManyCellFactory(org.knime.base.node.preproc.columntrans2.One2ManyCellFactory) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 15 with DerivedFieldMapper

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;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) DataColumnSpec(org.knime.core.data.DataColumnSpec) HashMap(java.util.HashMap) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField)

Aggregations

DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)37 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)11 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)11 PMML (org.dmg.pmml.PMMLDocument.PMML)9 DataTableSpec (org.knime.core.data.DataTableSpec)8 DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)7 BufferedDataTable (org.knime.core.node.BufferedDataTable)7 PortObject (org.knime.core.node.port.PortObject)7 ArrayList (java.util.ArrayList)4 NeuralNetwork (org.dmg.pmml.NeuralNetworkDocument.NeuralNetwork)4 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)4 MININGFUNCTION (org.dmg.pmml.MININGFUNCTION)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 DataType (org.knime.core.data.DataType)3 BigInteger (java.math.BigInteger)2 HashMap (java.util.HashMap)2 SchemaType (org.apache.xmlbeans.SchemaType)2 ACTIVATIONFUNCTION (org.dmg.pmml.ACTIVATIONFUNCTION)2 ArrayType (org.dmg.pmml.ArrayType)2 ClusterDocument (org.dmg.pmml.ClusterDocument)2