Search in sources :

Example 11 with TreeEnsembleModelPortObjectSpec

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

the class RandomForestRegressionPredictorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    TreeEnsembleModelPortObjectSpec modelSpec = (TreeEnsembleModelPortObjectSpec) inSpecs[0];
    String targetColName = modelSpec.getTargetColumn().getName();
    if (m_configuration == null) {
        m_configuration = TreeEnsemblePredictorConfiguration.createDefault(false, targetColName);
    }
    modelSpec.assertTargetTypeMatches(true);
    DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
    final TreeEnsemblePredictor pred = new TreeEnsemblePredictor(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) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec) TreeEnsemblePredictor(org.knime.base.node.mine.treeensemble.node.predictor.TreeEnsemblePredictor)

Example 12 with TreeEnsembleModelPortObjectSpec

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

the class TreeEnsembleClassificationPredictorNodeModel method execute.

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

Example 13 with TreeEnsembleModelPortObjectSpec

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

the class TreeEnsembleClassificationPredictorCellFactory method createFactory.

/**
 * Creates a TreeEnsembleClassificationPredictorCellFactory from the provided <b>predictor</b>
 * @param predictor
 * @return an instance of TreeEnsembleClassificationPredictorCellFactory configured according to the settings of the provided
 * <b>predictor<b>
 * @throws InvalidSettingsException
 */
public static TreeEnsembleClassificationPredictorCellFactory createFactory(final TreeEnsemblePredictor predictor) throws InvalidSettingsException {
    DataTableSpec testDataSpec = predictor.getDataSpec();
    TreeEnsembleModelPortObjectSpec modelSpec = predictor.getModelSpec();
    TreeEnsembleModelPortObject modelObject = predictor.getModelObject();
    TreeEnsemblePredictorConfiguration configuration = predictor.getConfiguration();
    UniqueNameGenerator nameGen = new UniqueNameGenerator(testDataSpec);
    Map<String, DataCell> targetValueMap = modelSpec.getTargetColumnPossibleValueMap();
    List<DataColumnSpec> newColsList = new ArrayList<DataColumnSpec>();
    DataType targetColType = modelSpec.getTargetColumn().getType();
    String targetColName = configuration.getPredictionColumnName();
    DataColumnSpec targetCol = nameGen.newColumn(targetColName, targetColType);
    newColsList.add(targetCol);
    if (configuration.isAppendPredictionConfidence()) {
        newColsList.add(nameGen.newColumn(targetCol.getName() + " (Confidence)", DoubleCell.TYPE));
    }
    if (configuration.isAppendClassConfidences()) {
        // and this class is not called)
        assert targetValueMap != null : "Target column has no possible values";
        for (String v : targetValueMap.keySet()) {
            newColsList.add(nameGen.newColumn(v, DoubleCell.TYPE));
        }
    }
    if (configuration.isAppendModelCount()) {
        newColsList.add(nameGen.newColumn("model count", IntCell.TYPE));
    }
    // assigned
    assert modelObject == null || targetValueMap != null : "Target values must be known during execution";
    DataColumnSpec[] newCols = newColsList.toArray(new DataColumnSpec[newColsList.size()]);
    int[] learnColumnInRealDataIndices = modelSpec.calculateFilterIndices(testDataSpec);
    return new TreeEnsembleClassificationPredictorCellFactory(predictor, targetValueMap, newCols, learnColumnInRealDataIndices);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec) TreeEnsemblePredictorConfiguration(org.knime.base.node.mine.treeensemble.node.predictor.TreeEnsemblePredictorConfiguration) ArrayList(java.util.ArrayList) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObject) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataCell(org.knime.core.data.DataCell) DataType(org.knime.core.data.DataType)

Example 14 with TreeEnsembleModelPortObjectSpec

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

the class TreeEnsembleRegressionPredictorCellFactory method createFactory.

/**
 * Creates a TreeEnsembleRegressionPredictorCellFactory from the provided <b>predictor</b>
 *
 * @param predictor
 * @return an instance of TreeEnsembleRegressionPredictorCellFactory configured according to the settings of the provided
 * <b>predictor<b>
 * @throws InvalidSettingsException
 */
public static TreeEnsembleRegressionPredictorCellFactory createFactory(final TreeEnsemblePredictor predictor) throws InvalidSettingsException {
    DataTableSpec testDataSpec = predictor.getDataSpec();
    TreeEnsembleModelPortObjectSpec modelSpec = predictor.getModelSpec();
    // TreeEnsembleModelPortObject modelObject = predictor.getModelObject();
    TreeEnsemblePredictorConfiguration 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);
    if (configuration.isAppendPredictionConfidence()) {
        newColsList.add(nameGen.newColumn(targetCol.getName() + " (Prediction Variance)", DoubleCell.TYPE));
    }
    if (configuration.isAppendModelCount()) {
        newColsList.add(nameGen.newColumn("model count", IntCell.TYPE));
    }
    DataColumnSpec[] newCols = newColsList.toArray(new DataColumnSpec[newColsList.size()]);
    int[] learnColumnInRealDataIndices = modelSpec.calculateFilterIndices(testDataSpec);
    return new TreeEnsembleRegressionPredictorCellFactory(predictor, newCols, learnColumnInRealDataIndices);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec) TreeEnsemblePredictorConfiguration(org.knime.base.node.mine.treeensemble.node.predictor.TreeEnsemblePredictorConfiguration) ArrayList(java.util.ArrayList) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Example 15 with TreeEnsembleModelPortObjectSpec

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

the class RandomForestRegressionPredictorNodeModel method execute.

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

Aggregations

TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec)22 DataTableSpec (org.knime.core.data.DataTableSpec)22 TreeEnsemblePredictor (org.knime.base.node.mine.treeensemble.node.predictor.TreeEnsemblePredictor)18 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)18 TreeEnsembleModelPortObject (org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObject)11 FilterLearnColumnRearranger (org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger)9 BufferedDataTable (org.knime.core.node.BufferedDataTable)9 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)9 TreeData (org.knime.base.node.mine.treeensemble.data.TreeData)5 TreeDataCreator (org.knime.base.node.mine.treeensemble.data.TreeDataCreator)5 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)5 PortObject (org.knime.core.node.port.PortObject)5 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)5 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 TreeEnsembleLearner (org.knime.base.node.mine.treeensemble.learner.TreeEnsembleLearner)4 TreeEnsembleModel (org.knime.base.node.mine.treeensemble.model.TreeEnsembleModel)4 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)4 DataCell (org.knime.core.data.DataCell)3 ArrayList (java.util.ArrayList)2