use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.
the class LogRegLearnerNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
final BufferedDataTable data = (BufferedDataTable) inObjects[0];
DataTableSpec tableSpec = data.getDataTableSpec();
// handle the optional PMML input
PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
PMMLPortObjectSpec inPMMLSpec = null;
if (inPMMLPort != null) {
inPMMLSpec = inPMMLPort.getSpec();
} else {
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(tableSpec);
inPMMLSpec = creator.createSpec();
inPMMLPort = new PMMLPortObject(inPMMLSpec);
}
LogRegLearner learner = new LogRegLearner(new PortObjectSpec[] { tableSpec, inPMMLSpec }, m_pmmlInEnabled, m_settings);
m_content = learner.execute(new PortObject[] { data, inPMMLPort }, exec);
String warn = learner.getWarningMessage();
if (warn != null) {
setWarningMessage(warn);
}
// third argument is ignored since we provide a port
PMMLPortObject outPMMLPort = new PMMLPortObject((PMMLPortObjectSpec) learner.getOutputSpec()[0], inPMMLPort, null);
PMMLGeneralRegressionTranslator trans = new PMMLGeneralRegressionTranslator(m_content.createGeneralRegressionContent());
outPMMLPort.addModelTranslater(trans);
return new PortObject[] { outPMMLPort, m_content.createTablePortObject(exec) };
}
use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.
the class PolyRegLearnerNodeModel method createPMMLModel.
private PMMLPortObject createPMMLModel(final PMMLPortObject inPMMLPort, final DataTableSpec inSpec) throws InvalidSettingsException, SAXException {
NumericPredictor[] preds = new NumericPredictor[m_betas.length - 1];
int deg = m_settings.getDegree();
for (int i = 0; i < m_columnNames.length; i++) {
for (int k = 0; k < deg; k++) {
preds[i * deg + k] = new NumericPredictor(m_columnNames[i], k + 1, m_betas[i * deg + k + 1]);
}
}
RegressionTable tab = new RegressionTable(m_betas[0], preds);
PMMLPortObjectSpec pmmlSpec = null;
if (inPMMLPort != null) {
pmmlSpec = inPMMLPort.getSpec();
}
PMMLPortObjectSpec spec = createModelSpec(pmmlSpec, inSpec);
/* To maintain compatibility with the previous SAX-based implementation.
* */
String targetField = "Response";
List<String> targetFields = spec.getTargetFields();
if (!targetFields.isEmpty()) {
targetField = targetFields.get(0);
}
PMMLPortObject outPMMLPort = new PMMLPortObject(spec, inPMMLPort, inSpec);
PMMLRegressionTranslator trans = new PMMLRegressionTranslator("KNIME Polynomial Regression", "PolynomialRegression", tab, targetField);
outPMMLPort.addModelTranslater(trans);
return outPMMLPort;
}
use of org.knime.core.node.port.pmml.PMMLPortObject 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 regModel = (PMMLPortObject) inData[0];
List<Node> models = regModel.getPMMLValue().getModels(PMMLModelType.RegressionModel);
if (models.isEmpty()) {
String msg = "No Regression Model found.";
LOGGER.error(msg);
throw new RuntimeException(msg);
}
PMMLRegressionTranslator trans = new PMMLRegressionTranslator();
regModel.initializeModelTranslator(trans);
BufferedDataTable data = (BufferedDataTable) inData[1];
DataTableSpec spec = data.getDataTableSpec();
ColumnRearranger c = createRearranger(spec, regModel.getSpec(), trans);
BufferedDataTable out = exec.createColumnRearrangeTable(data, c, exec);
return new BufferedDataTable[] { out };
}
use of org.knime.core.node.port.pmml.PMMLPortObject in project knime-core by knime.
the class TreeEnsembleModelPortObject method createDecisionTreePMMLPortObject.
public PMMLPortObject createDecisionTreePMMLPortObject(final int modelIndex) {
final TreeEnsembleModel ensembleModel = getEnsembleModel();
DataTableSpec attributeLearnSpec = ensembleModel.getLearnAttributeSpec(m_spec.getLearnTableSpec());
DataColumnSpec targetSpec = m_spec.getTargetColumn();
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(new DataTableSpec(attributeLearnSpec, new DataTableSpec(targetSpec)));
try {
pmmlSpecCreator.setLearningCols(attributeLearnSpec);
} catch (InvalidSettingsException e) {
// (as of KNIME v2.5.1)
throw new IllegalStateException(e);
}
pmmlSpecCreator.setTargetCol(targetSpec);
PMMLPortObjectSpec pmmlSpec = pmmlSpecCreator.createSpec();
PMMLPortObject portObject = new PMMLPortObject(pmmlSpec);
final AbstractTreeModel<?> model = ensembleModel.getTreeModel(modelIndex);
portObject.addModelTranslater(new TreeModelPMMLTranslator(model));
return portObject;
}
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() };
}
Aggregations