Search in sources :

Example 6 with GradientBoostingPredictor

use of org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor in project knime-core by knime.

the class GradientBoostingPredictorNodeModel 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 {
            GradientBoostingModelPortObject model = (GradientBoostingModelPortObject) ((PortObjectInput) inputs[0]).getPortObject();
            TreeEnsembleModelPortObjectSpec modelSpec = model.getSpec();
            DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
            final GradientBoostingPredictor<GradientBoostedTreesModel> pred = new GradientBoostingPredictor<>((GradientBoostedTreesModel) model.getEnsembleModel(), modelSpec, dataSpec, m_configuration);
            ColumnRearranger rearranger = pred.getPredictionRearranger();
            StreamableFunction func = rearranger.createStreamableFunction(1, 0);
            func.runFinal(inputs, outputs, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) GradientBoostingModelPortObject(org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) GradientBoostingPredictor(org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor) GradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.GradientBoostedTreesModel) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Example 7 with GradientBoostingPredictor

use of org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor in project knime-core by knime.

the class GradientBoostingPredictorNodeModel method execute.

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

Example 8 with GradientBoostingPredictor

use of org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor 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() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) MultiClassGradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel) GradientBoostingPredictor(org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec)

Example 9 with GradientBoostingPredictor

use of org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor 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);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) TreeEnsemblePredictorConfiguration(org.knime.base.node.mine.treeensemble2.node.predictor.TreeEnsemblePredictorConfiguration) ArrayList(java.util.ArrayList) DataCell(org.knime.core.data.DataCell) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Example 10 with GradientBoostingPredictor

use of org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor in project knime-core by knime.

the class GradientBoostingPMMLPredictorNodeModel 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];
            GradientBoostingModelPortObject gbt = importModel(model);
            final GradientBoostingPredictor<?> pred = new GradientBoostingPredictor<>(gbt.getEnsembleModel(), gbt.getSpec(), dataSpec, m_configuration);
            ColumnRearranger rearranger = pred.getPredictionRearranger();
            StreamableFunction func = rearranger.createStreamableFunction(1, 0);
            func.runFinal(inputs, outputs, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) GradientBoostingModelPortObject(org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) GradientBoostingPredictor(org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Aggregations

DataTableSpec (org.knime.core.data.DataTableSpec)12 TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec)10 GradientBoostingPredictor (org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor)9 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)8 GradientBoostingModelPortObject (org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject)6 MultiClassGradientBoostedTreesModel (org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel)5 GradientBoostedTreesModel (org.knime.base.node.mine.treeensemble2.model.GradientBoostedTreesModel)4 BufferedDataTable (org.knime.core.node.BufferedDataTable)3 ExecutionContext (org.knime.core.node.ExecutionContext)3 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)3 StreamableFunction (org.knime.core.node.streamable.StreamableFunction)3 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)2 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)2 UniqueNameGenerator (org.knime.core.util.UniqueNameGenerator)2 ArrayList (java.util.ArrayList)1 TreeEnsemblePredictorConfiguration (org.knime.base.node.mine.treeensemble2.node.predictor.TreeEnsemblePredictorConfiguration)1 DataCell (org.knime.core.data.DataCell)1 DataType (org.knime.core.data.DataType)1 StringValue (org.knime.core.data.StringValue)1