use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class FromDecisionTreeNodeModel method execute.
/**
* {@inheritDoc}
* @throws CanceledExecutionException Execution cancelled.
* @throws InvalidSettingsException No or more than one RuleSet model is in the PMML input.
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, InvalidSettingsException {
PMMLPortObject decTreeModel = (PMMLPortObject) inData[0];
PMMLDecisionTreeTranslator treeTranslator = new PMMLDecisionTreeTranslator();
decTreeModel.initializeModelTranslator(treeTranslator);
DecisionTree decisionTree = treeTranslator.getDecisionTree();
decisionTree.getRootNode();
PMMLPortObject ruleSetModel = new PMMLPortObject(decTreeModel.getSpec());
PMMLDocument document = PMMLDocument.Factory.newInstance();
PMML pmml = document.addNewPMML();
PMMLPortObjectSpec.writeHeader(pmml);
pmml.setVersion(PMMLPortObject.PMML_V4_2);
new PMMLDataDictionaryTranslator().exportTo(document, decTreeModel.getSpec());
RuleSetModel newRuleSetModel = pmml.addNewRuleSetModel();
PMMLMiningSchemaTranslator.writeMiningSchema(decTreeModel.getSpec(), newRuleSetModel);
newRuleSetModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
newRuleSetModel.setAlgorithmName("RuleSet");
RuleSet ruleSet = newRuleSetModel.addNewRuleSet();
ruleSet.addNewRuleSelectionMethod().setCriterion(Criterion.FIRST_HIT);
addRules(ruleSet, new ArrayList<DecisionTreeNode>(), decisionTree.getRootNode());
// TODO: Return a BufferedDataTable for each output port
PMMLPortObject pmmlPortObject = new PMMLPortObject(ruleSetModel.getSpec(), document);
return new PortObject[] { pmmlPortObject, new RuleSetToTable(m_rulesToTable).execute(exec, pmmlPortObject) };
}
use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class PMMLRuleEditorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
final BufferedDataTable table = (BufferedDataTable) inData[0];
RearrangerAndPMMLModel m = createRearrangerAndPMMLModel(table.getDataTableSpec());
return new PortObject[] { exec.createColumnRearrangeTable(table, m.getRearranger(), exec), m.getPMMLPortObject() };
}
use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class DBGroupByNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
exec.setMessage("Retrieving metadata from database");
DatabasePortObject dbObject = (DatabasePortObject) inData[0];
DatabasePortObject outObject = new DatabasePortObject(createDbOutSpec(dbObject.getSpec(), false));
return new PortObject[] { outObject };
}
use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class NaiveBayesPredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
LOGGER.debug("Entering execute(inData, exec) of class " + "NaiveBayesPredictorNodeModel.");
// check input data
assert (inData != null && inData.length == 2 && inData[DATA_IN_PORT] != null && inData[MODEL_IN_PORT] != null);
final PortObject dataObject = inData[DATA_IN_PORT];
if (!(dataObject instanceof BufferedDataTable)) {
throw new IllegalArgumentException("Invalid input data");
}
final BufferedDataTable data = (BufferedDataTable) dataObject;
final PortObject modelObject = inData[MODEL_IN_PORT];
if (!(modelObject instanceof NaiveBayesPortObject)) {
throw new IllegalArgumentException("Invalid input data");
}
final NaiveBayesModel model = ((NaiveBayesPortObject) modelObject).getModel();
exec.setMessage("Classifying rows...");
if (model == null) {
throw new Exception("Node not properly configured. " + "No Naive Bayes Model available.");
}
final double laplaceCorrector = m_laplaceCorrector.getDoubleValue();
final NaiveBayesCellFactory appender = new NaiveBayesCellFactory(model, data.getDataTableSpec(), m_inclProbVals.getBooleanValue(), laplaceCorrector);
final ColumnRearranger rearranger = new ColumnRearranger(data.getDataTableSpec());
rearranger.append(appender);
final BufferedDataTable returnVal = exec.createColumnRearrangeTable(data, rearranger, exec);
LOGGER.debug("Exiting execute(inData, exec) of class " + "NaiveBayesPredictorNodeModel.");
return new PortObject[] { returnVal };
}
use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class RegressionPredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
public PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
PMMLPortObject port = (PMMLPortObject) inData[0];
List<Node> models = port.getPMMLValue().getModels(PMMLModelType.GeneralRegressionModel);
if (models.isEmpty()) {
LOGGER.warn("No regression models in the input PMML.");
@SuppressWarnings("deprecation") org.knime.base.node.mine.regression.predict.RegressionPredictorNodeModel regrPredictor = new org.knime.base.node.mine.regression.predict.RegressionPredictorNodeModel();
@SuppressWarnings("deprecation") PortObject[] regrPredOut = regrPredictor.execute(inData, exec);
if (regrPredOut.length > 0 && regrPredOut[0] instanceof BufferedDataTable) {
BufferedDataTable regrPredOutTable = (BufferedDataTable) regrPredOut[0];
// replace name of prediction column (the last column of regrPredOutTable)
return new PortObject[] { adjustSpecOfRegressionPredictorTable(regrPredOutTable, inData, exec) };
} else {
return regrPredOut;
}
}
PMMLGeneralRegressionTranslator trans = new PMMLGeneralRegressionTranslator();
port.initializeModelTranslator(trans);
BufferedDataTable data = (BufferedDataTable) inData[1];
DataTableSpec spec = data.getDataTableSpec();
ColumnRearranger c = createRearranger(trans.getContent(), port.getSpec(), spec);
BufferedDataTable out = exec.createColumnRearrangeTable(data, c, exec);
return new BufferedDataTable[] { out };
}
Aggregations