Search in sources :

Example 1 with GradientBoostingPredictor

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

the class GradientBoostingClassificationPredictorNodeModel 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<MultiClassGradientBoostedTreesModel> pred = new GradientBoostingPredictor<>((MultiClassGradientBoostedTreesModel) 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) MultiClassGradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel) 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)

Example 2 with GradientBoostingPredictor

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

the class GradientBoostingClassificationPredictorNodeModel 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();
    GradientBoostingPredictor<MultiClassGradientBoostedTreesModel> predictor = new GradientBoostingPredictor<>((MultiClassGradientBoostedTreesModel) model.getEnsembleModel(), modelSpec, dataSpec, m_configuration);
    ColumnRearranger rearranger = predictor.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) MultiClassGradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel) GradientBoostingPredictor(org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 3 with GradientBoostingPredictor

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

the class GradientBoostingPredictor method createPredictionRearranger.

/**
 * {@inheritDoc}
 */
@Override
protected ColumnRearranger createPredictionRearranger() throws InvalidSettingsException {
    TreeEnsembleModelPortObjectSpec modelSpec = getModelSpec();
    DataTableSpec dataSpec = getDataSpec();
    ColumnRearranger predictionRearranger;
    boolean hasPossibleValues = modelSpec.getTargetColumnPossibleValueMap() != null;
    if (modelSpec.getTargetColumn().getType().isCompatible(DoubleValue.class)) {
        predictionRearranger = new ColumnRearranger(dataSpec);
        @SuppressWarnings("unchecked") GradientBoostingPredictor<GradientBoostedTreesModel> pred = (GradientBoostingPredictor<GradientBoostedTreesModel>) this;
        predictionRearranger.append(GradientBoostingPredictorCellFactory.createFactory(pred));
    } else if (getConfiguration().isAppendClassConfidences() && !hasPossibleValues) {
        // can't add confidence columns (possible values unknown)
        predictionRearranger = null;
    } else {
        predictionRearranger = new ColumnRearranger(dataSpec);
        @SuppressWarnings("unchecked") GradientBoostingPredictor<MultiClassGradientBoostedTreesModel> pred = (GradientBoostingPredictor<MultiClassGradientBoostedTreesModel>) this;
        predictionRearranger.append(LKGradientBoostingPredictorCellFactory.createFactory(pred));
    }
    return predictionRearranger;
}
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) MultiClassGradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel) GradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.GradientBoostedTreesModel)

Example 4 with GradientBoostingPredictor

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

the class GradientBoostingPMMLPredictorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[0];
    DataType targetType = extractTargetType(pmmlSpec);
    if (m_isRegression && !targetType.isCompatible(DoubleValue.class)) {
        throw new InvalidSettingsException("This node expects a regression model.");
    } else if (!m_isRegression && !targetType.isCompatible(StringValue.class)) {
        throw new InvalidSettingsException("This node expectes a classification model.");
    }
    try {
        AbstractTreeModelPMMLTranslator.checkPMMLSpec(pmmlSpec);
    } catch (IllegalArgumentException e) {
        throw new InvalidSettingsException(e.getMessage());
    }
    TreeEnsembleModelPortObjectSpec modelSpec = translateSpec(pmmlSpec);
    String targetColName = modelSpec.getTargetColumn().getName();
    if (m_configuration == null) {
        m_configuration = TreeEnsemblePredictorConfiguration.createDefault(m_isRegression, targetColName);
    } else if (!m_configuration.isChangePredictionColumnName()) {
        m_configuration.setPredictionColumnName(TreeEnsemblePredictorConfiguration.getPredictColumnName(targetColName));
    }
    modelSpec.assertTargetTypeMatches(m_isRegression);
    DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
    final GradientBoostingPredictor<GradientBoostedTreesModel> pred = new GradientBoostingPredictor<>(null, modelSpec, dataSpec, m_configuration);
    return new PortObjectSpec[] { pred.getPredictionRearranger().createSpec() };
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) GradientBoostingPredictor(org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DataType(org.knime.core.data.DataType) GradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.GradientBoostedTreesModel) MultiClassGradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel) StringValue(org.knime.core.data.StringValue)

Example 5 with GradientBoostingPredictor

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

the class GradientBoostingPMMLPredictorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
public PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    PMMLPortObject pmmlPO = (PMMLPortObject) inObjects[0];
    GradientBoostingModelPortObject model = importModel(pmmlPO);
    BufferedDataTable data = (BufferedDataTable) inObjects[1];
    DataTableSpec dataSpec = data.getDataTableSpec();
    // only happens if configure was not called previously e.g. in the generic PMML predictor
    if (m_configuration == null) {
        m_configuration = TreeEnsemblePredictorConfiguration.createDefault(m_isRegression, translateSpec(pmmlPO.getSpec()).getTargetColumn().getName());
    }
    final GradientBoostingPredictor<?> pred = new GradientBoostingPredictor<>(model.getEnsembleModel(), model.getSpec(), 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) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) GradientBoostingPredictor(org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor) BufferedDataTable(org.knime.core.node.BufferedDataTable)

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