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