Search in sources :

Example 11 with PMMLPortObject

use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.

the class RegressionTreePMMLPredictorNodeModel 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 {
            PMMLPortObject model = (PMMLPortObject) ((PortObjectInput) inputs[0]).getPortObject();
            DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
            Pair<RegressionTreeModel, RegressionTreeModelPortObjectSpec> treeSpecPair = importModel(model);
            final RegressionTreePredictor pred = new RegressionTreePredictor(treeSpecPair.getFirst(), treeSpecPair.getSecond(), dataSpec, m_configuration);
            ColumnRearranger rearranger = pred.getPredictionRearranger();
            StreamableFunction func = rearranger.createStreamableFunction(1, 0);
            func.runFinal(inputs, outputs, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) RegressionTreeModel(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Example 12 with PMMLPortObject

use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.

the class GBTPMMLExporterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    GradientBoostingModelPortObject gbtPO = (GradientBoostingModelPortObject) inObjects[0];
    AbstractGBTModelPMMLTranslator<?> translator;
    AbstractGradientBoostingModel gbtModel = gbtPO.getEnsembleModel();
    if (gbtModel instanceof GradientBoostedTreesModel) {
        translator = new RegressionGBTModelPMMLTranslator((GradientBoostedTreesModel) gbtModel, gbtPO.getSpec().getLearnTableSpec());
    } else if (gbtModel instanceof MultiClassGradientBoostedTreesModel) {
        translator = new ClassificationGBTModelPMMLTranslator((MultiClassGradientBoostedTreesModel) gbtModel, gbtPO.getSpec().getLearnTableSpec());
    } else {
        throw new IllegalArgumentException("Unknown gradient boosted trees model type '" + gbtModel.getClass().getSimpleName() + "'.");
    }
    PMMLPortObjectSpec pmmlSpec = createPMMLSpec(gbtPO.getSpec(), gbtModel);
    PMMLPortObject pmmlPO = new PMMLPortObject(pmmlSpec);
    pmmlPO.addModelTranslater(translator);
    return new PortObject[] { pmmlPO };
}
Also used : ClassificationGBTModelPMMLTranslator(org.knime.base.node.mine.treeensemble2.model.pmml.ClassificationGBTModelPMMLTranslator) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) GradientBoostingModelPortObject(org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) MultiClassGradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel) AbstractGradientBoostingModel(org.knime.base.node.mine.treeensemble2.model.AbstractGradientBoostingModel) GradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.GradientBoostedTreesModel) MultiClassGradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel) RegressionGBTModelPMMLTranslator(org.knime.base.node.mine.treeensemble2.model.pmml.RegressionGBTModelPMMLTranslator) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) GradientBoostingModelPortObject(org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject)

Example 13 with PMMLPortObject

use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.

the class GradientBoostingPMMLPredictorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
public PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    PMMLPortObject pmmlPO = (PMMLPortObject) inObjects[0];
    GradientBoostingModelPortObject model = importModel(pmmlPO);
    BufferedDataTable data = (BufferedDataTable) inObjects[1];
    DataTableSpec dataSpec = data.getDataTableSpec();
    // only happens if configure was not called previously e.g. in the generic PMML predictor
    if (m_configuration == null) {
        m_configuration = TreeEnsemblePredictorConfiguration.createDefault(m_isRegression, translateSpec(pmmlPO.getSpec()).getTargetColumn().getName());
    }
    final GradientBoostingPredictor<?> pred = new GradientBoostingPredictor<>(model.getEnsembleModel(), model.getSpec(), dataSpec, m_configuration);
    ColumnRearranger rearranger = pred.getPredictionRearranger();
    BufferedDataTable outTable = exec.createColumnRearrangeTable(data, rearranger, exec);
    return new BufferedDataTable[] { outTable };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) GradientBoostingModelPortObject(org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) GradientBoostingPredictor(org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 14 with PMMLPortObject

use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.

the class TreeEnsembleModelExtractorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    TreeEnsembleModelPortObject treeEnsembleModel = (TreeEnsembleModelPortObject) inObjects[0];
    DataTableSpec outSpec = createOutSpec();
    BufferedDataContainer container = exec.createDataContainer(outSpec, false, 0);
    int nrModels = treeEnsembleModel.getEnsembleModel().getNrModels();
    for (int i = 0; i < nrModels; i++) {
        PMMLPortObject pmmlObject = treeEnsembleModel.createDecisionTreePMMLPortObject(i);
        DataCell cell = PMMLCellFactory.create(pmmlObject.getPMMLValue().toString());
        RowKey key = RowKey.createRowKey(i);
        container.addRowToTable(new DefaultRow(key, cell));
        exec.checkCanceled();
        exec.setProgress(i / (double) nrModels, "Exported model " + (i + 1) + "/" + nrModels);
    }
    container.close();
    return new BufferedDataTable[] { container.getTable() };
}
Also used : TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) RowKey(org.knime.core.data.RowKey) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 15 with PMMLPortObject

use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.

the class Many2OneColPMMLNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    BufferedDataTable inData = (BufferedDataTable) inObjects[0];
    AbstractMany2OneCellFactory cellFactory = getCellFactory(inData.getDataTableSpec());
    BufferedDataTable outData = exec.createColumnRearrangeTable(inData, createRearranger(inData.getDataTableSpec(), cellFactory), exec);
    if (m_pmmlEnabled) {
        if (IncludeMethod.valueOf(m_includeMethod.getStringValue()) == IncludeMethod.RegExpPattern) {
            setWarningMessage("Regular Expressions are not supported in PMML. " + "The generated PMML document is invalid.");
        }
        // the optional PMML in port (can be null)
        PMMLPortObject inPMMLPort = (PMMLPortObject) inObjects[1];
        /*
             PMMLOne2ManyTranslator trans = new PMMLOne2ManyTranslator(
                    cellFactory.getColumnMapping(),
                    new DerivedFieldMapper(inPMMLPort));
            */
        int[] sourceColIndices = cellFactory.getIncludedColIndices();
        String[] sourceColNames = new String[sourceColIndices.length];
        for (int i = 0; i < sourceColIndices.length; i++) {
            sourceColNames[i] = inData.getDataTableSpec().getColumnSpec(sourceColIndices[i]).getName();
        }
        PMMLMany2OneTranslator trans = new PMMLMany2OneTranslator(cellFactory.getAppendedColumnName(), sourceColNames, IncludeMethod.valueOf(m_includeMethod.getStringValue()));
        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 : AbstractMany2OneCellFactory(org.knime.base.node.preproc.columnTrans.AbstractMany2OneCellFactory) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Aggregations

PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)90 BufferedDataTable (org.knime.core.node.BufferedDataTable)53 DataTableSpec (org.knime.core.data.DataTableSpec)50 PortObject (org.knime.core.node.port.PortObject)47 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)35 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)25 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)21 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)18 ExecutionContext (org.knime.core.node.ExecutionContext)13 DataColumnSpec (org.knime.core.data.DataColumnSpec)12 DataRow (org.knime.core.data.DataRow)12 DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)11 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)11 Node (org.w3c.dom.Node)10 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)9 IOException (java.io.IOException)8 DataCell (org.knime.core.data.DataCell)8 PMMLDocument (org.dmg.pmml.PMMLDocument)7 PMMLGeneralRegressionTranslator (org.knime.base.node.mine.regression.pmmlgreg.PMMLGeneralRegressionTranslator)7 StreamableFunction (org.knime.core.node.streamable.StreamableFunction)7