Search in sources :

Example 1 with RegressionTreeModel

use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel in project knime-core by knime.

the class RegressionTreeLearnerNodeView method newModel.

private void newModel() {
    assert SwingUtilities.isEventDispatchThread();
    final RegressionTreeLearnerNodeModel nodeModel = getNodeModel();
    RegressionTreeModel model = nodeModel.getRegressionTreeModel();
    DataTable hiliteRowSample = nodeModel.getHiliteRowSample();
    UpdateTreeWorker updateWorker = new UpdateTreeWorker(hiliteRowSample, model);
    UpdateTreeWorker old = m_updateWorkerRef.getAndSet(updateWorker);
    if (old != null) {
        old.cancel(true);
    }
    updateWorker.execute();
}
Also used : DataTable(org.knime.core.data.DataTable) RegressionTreeModel(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel)

Example 2 with RegressionTreeModel

use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel 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 RegressionTreeModel

use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel 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 RegressionTreeModel

use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel 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)

Example 5 with RegressionTreeModel

use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel in project knime-core by knime.

the class RegressionTreeModel method load.

/**
 * Loads and returns new ensemble model, input is NOT closed afterwards.
 *
 * @param in ...
 * @param exec ...
 * @return ...
 * @throws IOException ...
 * @throws CanceledExecutionException ...
 */
public static RegressionTreeModel load(final InputStream in, final ExecutionMonitor exec, final TreeBuildingInterner treeBuildingInterner) throws IOException, CanceledExecutionException {
    // wrapping the argument (zip input) stream in a buffered stream
    // reduces read operation from, e.g. 42s to 2s
    TreeModelDataInputStream input = new TreeModelDataInputStream(new BufferedInputStream(new NonClosableInputStream(in)));
    int version = input.readInt();
    if (version > 20140201) {
        throw new IOException("Tree Ensemble version " + version + " not supported");
    }
    TreeType type = TreeType.load(input);
    TreeMetaData metaData = TreeMetaData.load(input);
    boolean isRegression = metaData.isRegression();
    TreeModelRegression model;
    try {
        model = TreeModelRegression.load(input, metaData, treeBuildingInterner);
        if (input.readByte() != 0) {
            throw new IOException("Model not terminated by 0 byte");
        }
    } catch (IOException e) {
        throw new IOException("Can't read tree model. " + e.getMessage(), e);
    }
    // does not close the method argument stream!!
    input.close();
    return new RegressionTreeModel(metaData, model, type);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) NonClosableInputStream(org.knime.core.data.util.NonClosableInputStream) TreeMetaData(org.knime.base.node.mine.treeensemble2.data.TreeMetaData) IOException(java.io.IOException)

Aggregations

RegressionTreeModel (org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel)7 RegressionTreeModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec)5 DataTableSpec (org.knime.core.data.DataTableSpec)4 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)4 TreeModelRegression (org.knime.base.node.mine.treeensemble2.model.TreeModelRegression)3 RegressionTreeModelPMMLTranslator (org.knime.base.node.mine.treeensemble2.model.pmml.RegressionTreeModelPMMLTranslator)3 RegressionTreeModelPortObject (org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObject)2 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 BufferedDataTable (org.knime.core.node.BufferedDataTable)2 PortObject (org.knime.core.node.port.PortObject)2 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)2 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 RandomData (org.apache.commons.math.random.RandomData)1 FilterColumnRow (org.knime.base.data.filter.column.FilterColumnRow)1 PredictorRecord (org.knime.base.node.mine.treeensemble2.data.PredictorRecord)1 TreeData (org.knime.base.node.mine.treeensemble2.data.TreeData)1 TreeDataCreator (org.knime.base.node.mine.treeensemble2.data.TreeDataCreator)1 TreeMetaData (org.knime.base.node.mine.treeensemble2.data.TreeMetaData)1 BitVectorDataIndexManager (org.knime.base.node.mine.treeensemble2.data.memberships.BitVectorDataIndexManager)1