Search in sources :

Example 1 with RegressionGBTModelPMMLTranslator

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

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

Aggregations

GradientBoostingModelPortObject (org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject)2 ClassificationGBTModelPMMLTranslator (org.knime.base.node.mine.treeensemble2.model.pmml.ClassificationGBTModelPMMLTranslator)2 RegressionGBTModelPMMLTranslator (org.knime.base.node.mine.treeensemble2.model.pmml.RegressionGBTModelPMMLTranslator)2 AbstractGradientBoostingModel (org.knime.base.node.mine.treeensemble2.model.AbstractGradientBoostingModel)1 GradientBoostedTreesModel (org.knime.base.node.mine.treeensemble2.model.GradientBoostedTreesModel)1 MultiClassGradientBoostedTreesModel (org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel)1 TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec)1 AbstractGBTModelPMMLTranslator (org.knime.base.node.mine.treeensemble2.model.pmml.AbstractGBTModelPMMLTranslator)1 DataType (org.knime.core.data.DataType)1 StringValue (org.knime.core.data.StringValue)1 PortObject (org.knime.core.node.port.PortObject)1 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)1 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)1