Search in sources :

Example 1 with MultiClassGradientBoostedTreesModel

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

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

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

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

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

the class ClassificationGBTModelExporter method doWrite.

/**
 * {@inheritDoc}
 */
@Override
protected void doWrite(final MiningModel model) {
    Segmentation modelChain = model.addNewSegmentation();
    modelChain.setMultipleModelMethod(MULTIPLEMODELMETHOD.MODEL_CHAIN);
    MultiClassGradientBoostedTreesModel gbt = getGBTModel();
    // write one segment per class
    for (int i = 0; i < gbt.getNrClasses(); i++) {
        addClassSegment(modelChain, i);
    }
    // combine class predictions
    addAggregationSegment(modelChain);
}
Also used : Segmentation(org.dmg.pmml.SegmentationDocument.Segmentation) MultiClassGradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel)

Aggregations

MultiClassGradientBoostedTreesModel (org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel)7 TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec)5 DataTableSpec (org.knime.core.data.DataTableSpec)5 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)4 ArrayList (java.util.ArrayList)3 Segmentation (org.dmg.pmml.SegmentationDocument.Segmentation)3 GradientBoostingModelPortObject (org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject)3 TreeNodeSignature (org.knime.base.node.mine.treeensemble2.model.TreeNodeSignature)3 GradientBoostingPredictor (org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor)3 Map (java.util.Map)2 Segment (org.dmg.pmml.SegmentDocument.Segment)2 GradientBoostedTreesModel (org.knime.base.node.mine.treeensemble2.model.GradientBoostedTreesModel)2 TreeModelRegression (org.knime.base.node.mine.treeensemble2.model.TreeModelRegression)2 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 Semaphore (java.util.concurrent.Semaphore)1