use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.
the class RegressionTreeLearnerNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
// guaranteed to not be null (according to API)
DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
if (m_configuration == null) {
throw new InvalidSettingsException("No configuration available");
}
final FilterLearnColumnRearranger learnRearranger = m_configuration.filterLearnColumns(inSpec);
final String warn = learnRearranger.getWarning();
if (warn != null) {
setWarningMessage(warn);
}
m_configuration.checkColumnSelection(inSpec);
DataTableSpec learnSpec = learnRearranger.createSpec();
RegressionTreeModelPortObjectSpec treeSpec = new RegressionTreeModelPortObjectSpec(learnSpec);
return new PortObjectSpec[] { treeSpec };
}
use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.
the class RegressionTreePMMLTranslatorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
final RegressionTreeModelPortObject treePO = (RegressionTreeModelPortObject) inObjects[0];
final RegressionTreeModel model = treePO.getModel();
final RegressionTreeModelPortObjectSpec treeSpec = treePO.getSpec();
PMMLPortObjectSpec pmmlSpec = createPMMLSpec(treeSpec, model);
PMMLPortObject portObject = new PMMLPortObject(pmmlSpec);
final TreeModelRegression tree = model.getTreeModel();
final RegressionTreeModelPMMLTranslator translator = new RegressionTreeModelPMMLTranslator(tree, model.getMetaData(), treeSpec.getLearnTableSpec());
portObject.addModelTranslater(translator);
if (translator.hasWarning()) {
setWarningMessage(translator.getWarning());
}
return new PortObject[] { portObject };
}
use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.
the class RegressionTreePMMLPredictorNodeModel method importModel.
private Pair<RegressionTreeModel, RegressionTreeModelPortObjectSpec> importModel(final PMMLPortObject pmmlPO) {
RegressionTreeModelPMMLTranslator pmmlTranslator = new RegressionTreeModelPMMLTranslator();
pmmlPO.initializeModelTranslator(pmmlTranslator);
if (pmmlTranslator.hasWarning()) {
setWarningMessage(pmmlTranslator.getWarning());
}
return new Pair<>(new RegressionTreeModel(pmmlTranslator.getTreeMetaData(), pmmlTranslator.getTree(), TreeType.Ordinary), new RegressionTreeModelPortObjectSpec(pmmlTranslator.getLearnSpec()));
}
use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.
the class RegressionTreePMMLPredictorNodeModel method translateSpec.
private RegressionTreeModelPortObjectSpec translateSpec(final PMMLPortObjectSpec pmmlSpec) {
DataTableSpec pmmlDataSpec = pmmlSpec.getDataTableSpec();
ColumnRearranger cr = new ColumnRearranger(pmmlDataSpec);
List<DataColumnSpec> targets = pmmlSpec.getTargetCols();
CheckUtils.checkArgument(!targets.isEmpty(), "The provided PMML does not declare a target field.");
CheckUtils.checkArgument(targets.size() == 1, "The provided PMML declares multiple target. " + "This behavior is currently not supported.");
cr.move(targets.get(0).getName(), pmmlDataSpec.getNumColumns());
return new RegressionTreeModelPortObjectSpec(cr.createSpec());
}
use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec 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);
}
};
}
Aggregations