Search in sources :

Example 1 with RegressionTreeModelPortObjectSpec

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FilterLearnColumnRearranger(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec)

Example 2 with RegressionTreeModelPortObjectSpec

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 };
}
Also used : RegressionTreeModelPortObject(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObject) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) RegressionTreeModel(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec) RegressionTreeModelPortObject(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) TreeModelRegression(org.knime.base.node.mine.treeensemble2.model.TreeModelRegression) RegressionTreeModelPMMLTranslator(org.knime.base.node.mine.treeensemble2.model.pmml.RegressionTreeModelPMMLTranslator)

Example 3 with RegressionTreeModelPortObjectSpec

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()));
}
Also used : RegressionTreeModel(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec) RegressionTreeModelPMMLTranslator(org.knime.base.node.mine.treeensemble2.model.pmml.RegressionTreeModelPMMLTranslator) Pair(org.knime.core.util.Pair)

Example 4 with RegressionTreeModelPortObjectSpec

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());
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec)

Example 5 with RegressionTreeModelPortObjectSpec

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

Aggregations

RegressionTreeModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec)12 DataTableSpec (org.knime.core.data.DataTableSpec)9 RegressionTreeModel (org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel)5 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)5 RegressionTreeModelPortObject (org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObject)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 BufferedDataTable (org.knime.core.node.BufferedDataTable)3 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)3 TreeModelRegression (org.knime.base.node.mine.treeensemble2.model.TreeModelRegression)2 RegressionTreeModelPMMLTranslator (org.knime.base.node.mine.treeensemble2.model.pmml.RegressionTreeModelPMMLTranslator)2 FilterLearnColumnRearranger (org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 PortObject (org.knime.core.node.port.PortObject)2 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)2 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)2 ArrayList (java.util.ArrayList)1 RandomData (org.apache.commons.math.random.RandomData)1 TreeData (org.knime.base.node.mine.treeensemble2.data.TreeData)1 TreeDataCreator (org.knime.base.node.mine.treeensemble2.data.TreeDataCreator)1 BitVectorDataIndexManager (org.knime.base.node.mine.treeensemble2.data.memberships.BitVectorDataIndexManager)1