Search in sources :

Example 1 with RegressionTreeModelPortObjectSpec

use of org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.

the class RegressionTreeLearnerNodeModel method execute.

// /**
// * @param ensembleSpec
// * @param ensembleModel
// * @param inSpec
// * @return
// * @throws InvalidSettingsException
// */
// private TreeEnsemblePredictor createOutOfBagPredictor(final TreeEnsembleModelPortObjectSpec ensembleSpec,
// final TreeEnsembleModelPortObject ensembleModel, final DataTableSpec inSpec) throws InvalidSettingsException {
// TreeEnsemblePredictorConfiguration ooBConfig = new TreeEnsemblePredictorConfiguration(true);
// String targetColumn = m_configuration.getTargetColumn();
// String append = targetColumn + " (Out-of-bag)";
// ooBConfig.setPredictionColumnName(append);
// ooBConfig.setAppendPredictionConfidence(true);
// ooBConfig.setAppendClassConfidences(true);
// ooBConfig.setAppendModelCount(true);
// return new TreeEnsemblePredictor(ensembleSpec, ensembleModel, inSpec, ooBConfig);
// }
/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    BufferedDataTable t = (BufferedDataTable) inObjects[0];
    DataTableSpec spec = t.getDataTableSpec();
    final FilterLearnColumnRearranger learnRearranger = m_configuration.filterLearnColumns(spec);
    String warn = learnRearranger.getWarning();
    BufferedDataTable learnTable = exec.createColumnRearrangeTable(t, learnRearranger, exec.createSubProgress(0.0));
    DataTableSpec learnSpec = learnTable.getDataTableSpec();
    TreeEnsembleModelPortObjectSpec ensembleSpec = m_configuration.createPortObjectSpec(learnSpec);
    ExecutionMonitor readInExec = exec.createSubProgress(0.1);
    ExecutionMonitor learnExec = exec.createSubProgress(0.9);
    TreeDataCreator dataCreator = new TreeDataCreator(m_configuration, learnSpec, learnTable.getRowCount());
    exec.setProgress("Reading data into memory");
    TreeData data = dataCreator.readData(learnTable, m_configuration, readInExec);
    m_hiliteRowSample = dataCreator.getDataRowsForHilite();
    m_viewMessage = dataCreator.getViewMessage();
    String dataCreationWarning = dataCreator.getAndClearWarningMessage();
    if (dataCreationWarning != null) {
        if (warn == null) {
            warn = dataCreationWarning;
        } else {
            warn = warn + "\n" + dataCreationWarning;
        }
    }
    readInExec.setProgress(1.0);
    exec.setMessage("Learning tree");
    // TreeEnsembleLearner learner = new TreeEnsembleLearner(m_configuration, data);
    // TreeEnsembleModel model;
    // try {
    // model = learner.learnEnsemble(learnExec);
    // } catch (ExecutionException e) {
    // Throwable cause = e.getCause();
    // if (cause instanceof Exception) {
    // throw (Exception)cause;
    // }
    // throw e;
    // }
    RandomData rd = m_configuration.createRandomData();
    TreeLearnerRegression treeLearner = new TreeLearnerRegression(m_configuration, data, rd);
    TreeModelRegression regTree = treeLearner.learnSingleTree(learnExec, rd);
    RegressionTreeModel model = new RegressionTreeModel(m_configuration, data.getMetaData(), regTree, data.getTreeType());
    RegressionTreeModelPortObjectSpec treePortObjectSpec = new RegressionTreeModelPortObjectSpec(learnSpec);
    RegressionTreeModelPortObject treePortObject = new RegressionTreeModelPortObject(model, treePortObjectSpec);
    learnExec.setProgress(1.0);
    m_treeModelPortObject = treePortObject;
    if (warn != null) {
        setWarningMessage(warn);
    }
    return new PortObject[] { treePortObject };
}
Also used : RegressionTreeModelPortObject(org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) RandomData(org.apache.commons.math.random.RandomData) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec) RegressionTreeModel(org.knime.base.node.mine.treeensemble.model.RegressionTreeModel) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec) TreeModelRegression(org.knime.base.node.mine.treeensemble.model.TreeModelRegression) BufferedDataTable(org.knime.core.node.BufferedDataTable) FilterLearnColumnRearranger(org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger) TreeData(org.knime.base.node.mine.treeensemble.data.TreeData) TreeLearnerRegression(org.knime.base.node.mine.treeensemble.learner.TreeLearnerRegression) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) TreeDataCreator(org.knime.base.node.mine.treeensemble.data.TreeDataCreator) RegressionTreeModelPortObject(org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 2 with RegressionTreeModelPortObjectSpec

use of org.knime.base.node.mine.treeensemble.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);
    }
    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.treeensemble.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec)

Example 3 with RegressionTreeModelPortObjectSpec

use of org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.

the class RegressionTreePredictorCellFactory method createFactory.

/**
 * @param predictor
 * @return factory based on RegressionTreePredictor <b>predictor</b>
 * @throws InvalidSettingsException
 */
public static RegressionTreePredictorCellFactory createFactory(final RegressionTreePredictor predictor) throws InvalidSettingsException {
    DataTableSpec testDataSpec = predictor.getDataSpec();
    RegressionTreeModelPortObjectSpec modelSpec = predictor.getModelSpec();
    RegressionTreePredictorConfiguration configuration = predictor.getConfiguration();
    UniqueNameGenerator nameGen = new UniqueNameGenerator(testDataSpec);
    List<DataColumnSpec> newColsList = new ArrayList<DataColumnSpec>();
    String targetColName = configuration.getPredictionColumnName();
    DataColumnSpec targetCol = nameGen.newColumn(targetColName, DoubleCell.TYPE);
    newColsList.add(targetCol);
    DataColumnSpec[] newCols = newColsList.toArray(new DataColumnSpec[newColsList.size()]);
    int[] learnColumnInRealDataIndices = modelSpec.calculateFilterIndices(testDataSpec);
    return new RegressionTreePredictorCellFactory(predictor, newCols, learnColumnInRealDataIndices);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ArrayList(java.util.ArrayList) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Example 4 with RegressionTreeModelPortObjectSpec

use of org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.

the class RegressionTreePredictorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    RegressionTreeModelPortObjectSpec modelSpec = (RegressionTreeModelPortObjectSpec) inSpecs[0];
    String targetColName = modelSpec.getTargetColumn().getName();
    if (m_configuration == null) {
        m_configuration = RegressionTreePredictorConfiguration.createDefault(targetColName);
    } else if (!m_configuration.isChangePredictionColumnName()) {
        m_configuration.setPredictionColumnName(RegressionTreePredictorConfiguration.getPredictColumnName(targetColName));
    }
    // modelSpec.assertTargetTypeMatches(true);
    DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
    final RegressionTreePredictor pred = new RegressionTreePredictor(modelSpec, null, dataSpec, m_configuration);
    ColumnRearranger rearranger = pred.getPredictionRearranger();
    // rearranger may be null if confidence values are appended but the
    // model does not have a list of possible target values
    DataTableSpec outSpec = rearranger != null ? rearranger.createSpec() : null;
    return new DataTableSpec[] { outSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec)

Example 5 with RegressionTreeModelPortObjectSpec

use of org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.

the class RegressionTreePredictorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    RegressionTreeModelPortObject model = (RegressionTreeModelPortObject) inObjects[0];
    RegressionTreeModelPortObjectSpec modelSpec = model.getSpec();
    BufferedDataTable data = (BufferedDataTable) inObjects[1];
    DataTableSpec dataSpec = data.getDataTableSpec();
    final RegressionTreePredictor pred = new RegressionTreePredictor(modelSpec, model, dataSpec, m_configuration);
    ColumnRearranger rearranger = pred.getPredictionRearranger();
    BufferedDataTable outTable = exec.createColumnRearrangeTable(data, rearranger, exec);
    return new BufferedDataTable[] { outTable };
}
Also used : RegressionTreeModelPortObject(org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec)

Aggregations

RegressionTreeModelPortObjectSpec (org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec)5 DataTableSpec (org.knime.core.data.DataTableSpec)5 RegressionTreeModelPortObject (org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObject)2 TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec)2 FilterLearnColumnRearranger (org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger)2 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 BufferedDataTable (org.knime.core.node.BufferedDataTable)2 ArrayList (java.util.ArrayList)1 RandomData (org.apache.commons.math.random.RandomData)1 TreeData (org.knime.base.node.mine.treeensemble.data.TreeData)1 TreeDataCreator (org.knime.base.node.mine.treeensemble.data.TreeDataCreator)1 TreeLearnerRegression (org.knime.base.node.mine.treeensemble.learner.TreeLearnerRegression)1 RegressionTreeModel (org.knime.base.node.mine.treeensemble.model.RegressionTreeModel)1 TreeModelRegression (org.knime.base.node.mine.treeensemble.model.TreeModelRegression)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 PortObject (org.knime.core.node.port.PortObject)1 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)1 UniqueNameGenerator (org.knime.core.util.UniqueNameGenerator)1