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);
}
};
}
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 };
}
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 };
}
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() };
}
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 };
}
}
Aggregations