use of org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec in project knime-core by knime.
the class GradientBoostingClassificationPredictorNodeModel 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);
} else if (!m_configuration.isChangePredictionColumnName()) {
m_configuration.setPredictionColumnName(TreeEnsemblePredictorConfiguration.getPredictColumnName(targetColName));
}
modelSpec.assertTargetTypeMatches(false);
DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
GradientBoostingPredictor<MultiClassGradientBoostedTreesModel> predictor = new GradientBoostingPredictor<>(null, modelSpec, dataSpec, m_configuration);
ColumnRearranger rearranger = predictor.getPredictionRearranger();
return new PortObjectSpec[] { rearranger.createSpec() };
}
use of org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec in project knime-core by knime.
the class LKGradientBoostingPredictorCellFactory method createFactory.
public static LKGradientBoostingPredictorCellFactory createFactory(final GradientBoostingPredictor<MultiClassGradientBoostedTreesModel> predictor) throws InvalidSettingsException {
TreeEnsemblePredictorConfiguration config = predictor.getConfiguration();
DataTableSpec testSpec = predictor.getDataSpec();
TreeEnsembleModelPortObjectSpec modelSpec = predictor.getModelSpec();
ArrayList<DataColumnSpec> newColSpecs = new ArrayList<DataColumnSpec>();
UniqueNameGenerator nameGen = new UniqueNameGenerator(testSpec);
newColSpecs.add(nameGen.newColumn(config.getPredictionColumnName(), StringCell.TYPE));
if (config.isAppendPredictionConfidence()) {
newColSpecs.add(nameGen.newColumn("Confidence", DoubleCell.TYPE));
}
if (config.isAppendClassConfidences()) {
final String targetColName = modelSpec.getTargetColumn().getName();
final String suffix = config.getSuffixForClassProbabilities();
for (String val : modelSpec.getTargetColumnPossibleValueMap().keySet()) {
String colName = "P(" + targetColName + "=" + val + ")" + suffix;
newColSpecs.add(nameGen.newColumn(colName, DoubleCell.TYPE));
}
}
final Map<String, DataCell> targetValueMap = modelSpec.getTargetColumnPossibleValueMap();
return new LKGradientBoostingPredictorCellFactory(newColSpecs.toArray(new DataColumnSpec[newColSpecs.size()]), predictor.getModel(), modelSpec.getLearnTableSpec(), modelSpec.calculateFilterIndices(testSpec), config, targetValueMap);
}
use of org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec in project knime-core by knime.
the class GradientBoostingPredictorCellFactory method createFactory.
public static GradientBoostingPredictorCellFactory createFactory(final GradientBoostingPredictor<GradientBoostedTreesModel> predictor) throws InvalidSettingsException {
TreeEnsembleModelPortObjectSpec modelSpec = predictor.getModelSpec();
DataTableSpec learnSpec = modelSpec.getLearnTableSpec();
DataTableSpec testSpec = predictor.getDataSpec();
UniqueNameGenerator nameGen = new UniqueNameGenerator(testSpec);
DataColumnSpec newColSpec = nameGen.newColumn(predictor.getConfiguration().getPredictionColumnName(), DoubleCell.TYPE);
return new GradientBoostingPredictorCellFactory(newColSpec, predictor.getModel(), learnSpec, modelSpec.calculateFilterIndices(testSpec));
}
use of org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec in project knime-core by knime.
the class GradientBoostingPredictorNodeModel 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);
} else if (!m_configuration.isChangePredictionColumnName()) {
m_configuration.setPredictionColumnName(TreeEnsemblePredictorConfiguration.getPredictColumnName(targetColName));
}
modelSpec.assertTargetTypeMatches(true);
DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
final GradientBoostingPredictor pred = new GradientBoostingPredictor(null, modelSpec, dataSpec, m_configuration);
return new PortObjectSpec[] { pred.getPredictionRearranger().createSpec() };
}
use of org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec in project knime-core by knime.
the class TreeEnsembleClassificationLearnerNodeModel method createOutOfBagPredictor.
/**
* @param ensembleSpec
* @param ensembleModel
* @param inSpec
* @return
* @throws InvalidSettingsException
*/
private TreeEnsemblePredictor createOutOfBagPredictor(final TreeEnsembleModelPortObjectSpec ensembleSpec, final TreeEnsembleModelPortObject ensembleModel, final DataTableSpec inSpec) throws InvalidSettingsException {
String targetColumn = m_configuration.getTargetColumn();
TreeEnsemblePredictorConfiguration ooBConfig = new TreeEnsemblePredictorConfiguration(false, targetColumn);
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);
}
Aggregations