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