Search in sources :

Example 1 with GradientBoostingModelPortObject

use of org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject in project knime-core by knime.

the class GBTPMMLExporterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    GradientBoostingModelPortObject gbtPO = (GradientBoostingModelPortObject) inObjects[0];
    AbstractGBTModelPMMLTranslator<?> translator;
    AbstractGradientBoostingModel gbtModel = gbtPO.getEnsembleModel();
    if (gbtModel instanceof GradientBoostedTreesModel) {
        translator = new RegressionGBTModelPMMLTranslator((GradientBoostedTreesModel) gbtModel, gbtPO.getSpec().getLearnTableSpec());
    } else if (gbtModel instanceof MultiClassGradientBoostedTreesModel) {
        translator = new ClassificationGBTModelPMMLTranslator((MultiClassGradientBoostedTreesModel) gbtModel, gbtPO.getSpec().getLearnTableSpec());
    } else {
        throw new IllegalArgumentException("Unknown gradient boosted trees model type '" + gbtModel.getClass().getSimpleName() + "'.");
    }
    PMMLPortObjectSpec pmmlSpec = createPMMLSpec(gbtPO.getSpec(), gbtModel);
    PMMLPortObject pmmlPO = new PMMLPortObject(pmmlSpec);
    pmmlPO.addModelTranslater(translator);
    return new PortObject[] { pmmlPO };
}
Also used : ClassificationGBTModelPMMLTranslator(org.knime.base.node.mine.treeensemble2.model.pmml.ClassificationGBTModelPMMLTranslator) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) GradientBoostingModelPortObject(org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) MultiClassGradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel) AbstractGradientBoostingModel(org.knime.base.node.mine.treeensemble2.model.AbstractGradientBoostingModel) GradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.GradientBoostedTreesModel) MultiClassGradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel) RegressionGBTModelPMMLTranslator(org.knime.base.node.mine.treeensemble2.model.pmml.RegressionGBTModelPMMLTranslator) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) GradientBoostingModelPortObject(org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject)

Example 2 with GradientBoostingModelPortObject

use of org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject 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 3 with GradientBoostingModelPortObject

use of org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject 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 4 with GradientBoostingModelPortObject

use of org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject in project knime-core by knime.

the class GradientBoostingPMMLPredictorNodeModel method importModel.

@SuppressWarnings("unchecked")
private GradientBoostingModelPortObject importModel(final PMMLPortObject pmmlPO) {
    AbstractGBTModelPMMLTranslator<M> pmmlTranslator;
    DataType targetType = extractTargetType(pmmlPO.getSpec());
    if (targetType.isCompatible(DoubleValue.class)) {
        pmmlTranslator = (AbstractGBTModelPMMLTranslator<M>) new RegressionGBTModelPMMLTranslator();
    } else if (targetType.isCompatible(StringValue.class)) {
        pmmlTranslator = (AbstractGBTModelPMMLTranslator<M>) new ClassificationGBTModelPMMLTranslator();
    } else {
        throw new IllegalArgumentException("Currently only regression models are supported.");
    }
    pmmlPO.initializeModelTranslator(pmmlTranslator);
    if (pmmlTranslator.hasWarning()) {
        setWarningMessage(pmmlTranslator.getWarning());
    }
    return new GradientBoostingModelPortObject(new TreeEnsembleModelPortObjectSpec(pmmlTranslator.getLearnSpec()), pmmlTranslator.getGBTModel());
}
Also used : AbstractGBTModelPMMLTranslator(org.knime.base.node.mine.treeensemble2.model.pmml.AbstractGBTModelPMMLTranslator) ClassificationGBTModelPMMLTranslator(org.knime.base.node.mine.treeensemble2.model.pmml.ClassificationGBTModelPMMLTranslator) GradientBoostingModelPortObject(org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) DataType(org.knime.core.data.DataType) RegressionGBTModelPMMLTranslator(org.knime.base.node.mine.treeensemble2.model.pmml.RegressionGBTModelPMMLTranslator) StringValue(org.knime.core.data.StringValue)

Example 5 with GradientBoostingModelPortObject

use of org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject 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

GradientBoostingModelPortObject (org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject)10 DataTableSpec (org.knime.core.data.DataTableSpec)8 TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec)7 GradientBoostingPredictor (org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor)6 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)6 BufferedDataTable (org.knime.core.node.BufferedDataTable)5 AbstractGradientBoostingModel (org.knime.base.node.mine.treeensemble2.model.AbstractGradientBoostingModel)3 GradientBoostedTreesModel (org.knime.base.node.mine.treeensemble2.model.GradientBoostedTreesModel)3 MultiClassGradientBoostedTreesModel (org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel)3 ExecutionContext (org.knime.core.node.ExecutionContext)3 PortObject (org.knime.core.node.port.PortObject)3 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)3 StreamableFunction (org.knime.core.node.streamable.StreamableFunction)3 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)3 TreeData (org.knime.base.node.mine.treeensemble2.data.TreeData)2 TreeDataCreator (org.knime.base.node.mine.treeensemble2.data.TreeDataCreator)2 AbstractGradientBoostingLearner (org.knime.base.node.mine.treeensemble2.learner.gradientboosting.AbstractGradientBoostingLearner)2 ClassificationGBTModelPMMLTranslator (org.knime.base.node.mine.treeensemble2.model.pmml.ClassificationGBTModelPMMLTranslator)2 RegressionGBTModelPMMLTranslator (org.knime.base.node.mine.treeensemble2.model.pmml.RegressionGBTModelPMMLTranslator)2 FilterLearnColumnRearranger (org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger)2