Search in sources :

Example 1 with RuleSetModel

use of org.dmg.pmml.RuleSetModelDocument.RuleSetModel in project knime-core by knime.

the class FromDecisionTreeNodeModel method execute.

/**
 * {@inheritDoc}
 * @throws CanceledExecutionException Execution cancelled.
 * @throws InvalidSettingsException No or more than one RuleSet model is in the PMML input.
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, InvalidSettingsException {
    PMMLPortObject decTreeModel = (PMMLPortObject) inData[0];
    PMMLDecisionTreeTranslator treeTranslator = new PMMLDecisionTreeTranslator();
    decTreeModel.initializeModelTranslator(treeTranslator);
    DecisionTree decisionTree = treeTranslator.getDecisionTree();
    decisionTree.getRootNode();
    PMMLPortObject ruleSetModel = new PMMLPortObject(decTreeModel.getSpec());
    PMMLDocument document = PMMLDocument.Factory.newInstance();
    PMML pmml = document.addNewPMML();
    PMMLPortObjectSpec.writeHeader(pmml);
    pmml.setVersion(PMMLPortObject.PMML_V4_2);
    new PMMLDataDictionaryTranslator().exportTo(document, decTreeModel.getSpec());
    RuleSetModel newRuleSetModel = pmml.addNewRuleSetModel();
    PMMLMiningSchemaTranslator.writeMiningSchema(decTreeModel.getSpec(), newRuleSetModel);
    newRuleSetModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
    newRuleSetModel.setAlgorithmName("RuleSet");
    RuleSet ruleSet = newRuleSetModel.addNewRuleSet();
    ruleSet.addNewRuleSelectionMethod().setCriterion(Criterion.FIRST_HIT);
    addRules(ruleSet, new ArrayList<DecisionTreeNode>(), decisionTree.getRootNode());
    // TODO: Return a BufferedDataTable for each output port
    PMMLPortObject pmmlPortObject = new PMMLPortObject(ruleSetModel.getSpec(), document);
    return new PortObject[] { pmmlPortObject, new RuleSetToTable(m_rulesToTable).execute(exec, pmmlPortObject) };
}
Also used : RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) DecisionTree(org.knime.base.node.mine.decisiontree2.model.DecisionTree) PMMLDecisionTreeTranslator(org.knime.base.node.mine.decisiontree2.PMMLDecisionTreeTranslator) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PMML(org.dmg.pmml.PMMLDocument.PMML) DecisionTreeNodeSplitPMML(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML) PMMLDocument(org.dmg.pmml.PMMLDocument) PMMLDataDictionaryTranslator(org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator) PortObject(org.knime.core.node.port.PortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) RuleSetToTable(org.knime.base.node.rules.engine.totable.RuleSetToTable) DecisionTreeNode(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)

Example 2 with RuleSetModel

use of org.dmg.pmml.RuleSetModelDocument.RuleSetModel in project knime-core by knime.

the class PMMLRuleEditorNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
    return new StreamableOperator() {

        private ColumnRearranger m_rearrangerx;

        private PMMLPortObject m_portObject;

        {
            try {
                final PMMLDocument doc = PMMLDocument.Factory.newInstance();
                final PMML pmml = doc.addNewPMML();
                RuleSetModel ruleSetModel = pmml.addNewRuleSetModel();
                RuleSet ruleSet = ruleSetModel.addNewRuleSet();
                PMMLRuleParser parser = new PMMLRuleParser(tableSpec, getAvailableInputFlowVariables());
                m_rearrangerx = createRearranger(tableSpec, ruleSet, parser);
            } catch (ParseException e) {
                throw new InvalidSettingsException(e);
            }
        }

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            m_rearrangerx.createStreamableFunction(0, 0).runFinal(inputs, outputs, exec);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void loadInternals(final StreamableOperatorInternals internals) {
            super.loadInternals(internals);
            m_portObject = ((StreamInternalForPMMLPortObject) internals).getObject();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public StreamableOperatorInternals saveInternals() {
            return createInitialStreamableOperatorInternals().setObject(m_portObject);
        }
    };
}
Also used : RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) DataTableSpec(org.knime.core.data.DataTableSpec) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) ExecutionContext(org.knime.core.node.ExecutionContext) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMML(org.dmg.pmml.PMMLDocument.PMML) PMMLDocument(org.dmg.pmml.PMMLDocument) ParseException(java.text.ParseException)

Example 3 with RuleSetModel

use of org.dmg.pmml.RuleSetModelDocument.RuleSetModel in project knime-core by knime.

the class PMMLRuleSetPredictorNodeModel method createRearranger.

/**
 * Constructs the {@link ColumnRearranger} for computing the new columns.
 *
 * @param obj The {@link PMMLPortObject} of the preprocessing model.
 * @param spec The {@link DataTableSpec} of the table.
 * @param replaceColumn Should replace the {@code outputColumnName}?
 * @param outputColumnName The output column name (which might be an existing).
 * @param addConfidence Should add the confidence values to a column?
 * @param confidenceColumnName The name of the confidence column.
 * @param validationColumnIdx Index of the validation column, {@code -1} if not specified.
 * @param processConcurrently Should be {@code false} when the statistics are to be computed.
 * @return The {@link ColumnRearranger} computing the result.
 * @throws InvalidSettingsException Problem with rules.
 */
private static ColumnRearranger createRearranger(final PMMLPortObject obj, final DataTableSpec spec, final boolean replaceColumn, final String outputColumnName, final boolean addConfidence, final String confidenceColumnName, final int validationColumnIdx, final boolean processConcurrently) throws InvalidSettingsException {
    List<Node> models = obj.getPMMLValue().getModels(PMMLModelType.RuleSetModel);
    if (models.size() != 1) {
        throw new InvalidSettingsException("Expected exactly on RuleSetModel, but got: " + models.size());
    }
    final PMMLRuleTranslator translator = new PMMLRuleTranslator();
    obj.initializeModelTranslator(translator);
    if (!translator.isScorable()) {
        throw new UnsupportedOperationException("The model is not scorable.");
    }
    final List<PMMLRuleTranslator.Rule> rules = translator.getRules();
    ColumnRearranger ret = new ColumnRearranger(spec);
    final List<DataColumnSpec> targetCols = obj.getSpec().getTargetCols();
    final DataType dataType = targetCols.isEmpty() ? StringCell.TYPE : targetCols.get(0).getType();
    DataColumnSpecCreator specCreator = new DataColumnSpecCreator(outputColumnName, dataType);
    Set<DataCell> outcomes = new LinkedHashSet<>();
    for (Rule rule : rules) {
        DataCell outcome;
        if (dataType.equals(BooleanCell.TYPE)) {
            outcome = BooleanCellFactory.create(rule.getOutcome());
        } else if (dataType.equals(StringCell.TYPE)) {
            outcome = new StringCell(rule.getOutcome());
        } else if (dataType.equals(DoubleCell.TYPE)) {
            try {
                outcome = new DoubleCell(Double.parseDouble(rule.getOutcome()));
            } catch (NumberFormatException e) {
                // ignore
                continue;
            }
        } else if (dataType.equals(IntCell.TYPE)) {
            try {
                outcome = new IntCell(Integer.parseInt(rule.getOutcome()));
            } catch (NumberFormatException e) {
                // ignore
                continue;
            }
        } else if (dataType.equals(LongCell.TYPE)) {
            try {
                outcome = new LongCell(Long.parseLong(rule.getOutcome()));
            } catch (NumberFormatException e) {
                // ignore
                continue;
            }
        } else {
            throw new UnsupportedOperationException("Unknown outcome type: " + dataType);
        }
        outcomes.add(outcome);
    }
    specCreator.setDomain(new DataColumnDomainCreator(outcomes).createDomain());
    DataColumnSpec colSpec = specCreator.createSpec();
    final RuleSelectionMethod ruleSelectionMethod = translator.getSelectionMethodList().get(0);
    final String defaultScore = translator.getDefaultScore();
    final Double defaultConfidence = translator.getDefaultConfidence();
    final DataColumnSpec[] specs;
    if (addConfidence) {
        specs = new DataColumnSpec[] { new DataColumnSpecCreator(DataTableSpec.getUniqueColumnName(ret.createSpec(), confidenceColumnName), DoubleCell.TYPE).createSpec(), colSpec };
    } else {
        specs = new DataColumnSpec[] { colSpec };
    }
    final int oldColumnIndex = replaceColumn ? ret.indexOf(outputColumnName) : -1;
    ret.append(new AbstractCellFactory(processConcurrently, specs) {

        private final List<String> m_values;

        {
            Map<String, List<String>> dd = translator.getDataDictionary();
            m_values = dd.get(targetCols.get(0).getName());
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public DataCell[] getCells(final DataRow row) {
            // See http://www.dmg.org/v4-1/RuleSet.html#Rule
            switch(ruleSelectionMethod.getCriterion().intValue()) {
                case RuleSelectionMethod.Criterion.INT_FIRST_HIT:
                    {
                        Pair<DataCell, Double> resultAndConfidence = selectFirstHit(row);
                        return toCells(resultAndConfidence);
                    }
                case RuleSelectionMethod.Criterion.INT_WEIGHTED_MAX:
                    {
                        Pair<DataCell, Double> resultAndConfidence = selectWeightedMax(row);
                        return toCells(resultAndConfidence);
                    }
                case RuleSelectionMethod.Criterion.INT_WEIGHTED_SUM:
                    {
                        Pair<DataCell, Double> resultAndConfidence = selectWeightedSum(row);
                        return toCells(resultAndConfidence);
                    }
                default:
                    throw new UnsupportedOperationException(ruleSelectionMethod.getCriterion().toString());
            }
        }

        /**
         * Converts the pair to a {@link DataCell} array.
         *
         * @param resultAndConfidence The {@link Pair}.
         * @return The result and possibly the confidence.
         */
        private DataCell[] toCells(final Pair<DataCell, Double> resultAndConfidence) {
            if (!addConfidence) {
                return new DataCell[] { resultAndConfidence.getFirst() };
            }
            if (resultAndConfidence.getSecond() == null) {
                return new DataCell[] { DataType.getMissingCell(), resultAndConfidence.getFirst() };
            }
            return new DataCell[] { new DoubleCell(resultAndConfidence.getSecond()), resultAndConfidence.getFirst() };
        }

        /**
         * Computes the result and the confidence using the weighted sum method.
         *
         * @param row A {@link DataRow}
         * @return The result and the confidence.
         */
        private Pair<DataCell, Double> selectWeightedSum(final DataRow row) {
            final Map<String, Double> scoreToSumWeight = new LinkedHashMap<String, Double>();
            for (String val : m_values) {
                scoreToSumWeight.put(val, 0.0);
            }
            int matchedRuleCount = 0;
            for (final PMMLRuleTranslator.Rule rule : rules) {
                if (rule.getCondition().evaluate(row, spec) == Boolean.TRUE) {
                    ++matchedRuleCount;
                    Double sumWeight = scoreToSumWeight.get(rule.getOutcome());
                    if (sumWeight == null) {
                        throw new IllegalStateException("The score value: " + rule.getOutcome() + " is not in the data dictionary.");
                    }
                    final Double wRaw = rule.getWeight();
                    final double w = wRaw == null ? 0.0 : wRaw.doubleValue();
                    scoreToSumWeight.put(rule.getOutcome(), sumWeight + w);
                }
            }
            double maxSumWeight = Double.NEGATIVE_INFINITY;
            String bestScore = null;
            for (Entry<String, Double> entry : scoreToSumWeight.entrySet()) {
                final double d = entry.getValue().doubleValue();
                if (d > maxSumWeight) {
                    maxSumWeight = d;
                    bestScore = entry.getKey();
                }
            }
            if (bestScore == null || matchedRuleCount == 0) {
                return pair(result(defaultScore), defaultConfidence);
            }
            return pair(result(bestScore), maxSumWeight / matchedRuleCount);
        }

        /**
         * Helper method to create {@link Pair}s.
         *
         * @param f The first element.
         * @param s The second element.
         * @return The new pair.
         */
        private <F, S> Pair<F, S> pair(final F f, final S s) {
            return new Pair<F, S>(f, s);
        }

        /**
         * Computes the result and the confidence using the weighted max method.
         *
         * @param row A {@link DataRow}
         * @return The result and the confidence.
         */
        private Pair<DataCell, Double> selectWeightedMax(final DataRow row) {
            double maxWeight = Double.NEGATIVE_INFINITY;
            PMMLRuleTranslator.Rule bestRule = null;
            for (final PMMLRuleTranslator.Rule rule : rules) {
                if (rule.getCondition().evaluate(row, spec) == Boolean.TRUE) {
                    if (rule.getWeight() > maxWeight) {
                        maxWeight = rule.getWeight();
                        bestRule = rule;
                    }
                }
            }
            if (bestRule == null) {
                return pair(result(defaultScore), defaultConfidence);
            }
            bestRule.setRecordCount(bestRule.getRecordCount() + 1);
            DataCell result = result(bestRule);
            if (validationColumnIdx >= 0) {
                if (row.getCell(validationColumnIdx).equals(result)) {
                    bestRule.setNbCorrect(bestRule.getNbCorrect() + 1);
                }
            }
            Double confidence = bestRule.getConfidence();
            return pair(result, confidence == null ? defaultConfidence : confidence);
        }

        /**
         * Selects the outcome of the rule and converts it to the proper outcome type.
         *
         * @param rule A {@link Rule}.
         * @return The {@link DataCell} representing the result. (May be missing.)
         */
        private DataCell result(final PMMLRuleTranslator.Rule rule) {
            String outcome = rule.getOutcome();
            return result(outcome);
        }

        /**
         * Constructs the {@link DataCell} from its {@link String} representation ({@code outcome}) and its type.
         *
         * @param dataType The expected {@link DataType}
         * @param outcome The {@link String} representation.
         * @return The {@link DataCell}.
         */
        private DataCell result(final String outcome) {
            if (outcome == null) {
                return DataType.getMissingCell();
            }
            try {
                if (dataType.isCompatible(BooleanValue.class)) {
                    return BooleanCellFactory.create(outcome);
                }
                if (IntCell.TYPE.isASuperTypeOf(dataType)) {
                    return new IntCell(Integer.parseInt(outcome));
                }
                if (LongCell.TYPE.isASuperTypeOf(dataType)) {
                    return new LongCell(Long.parseLong(outcome));
                }
                if (DoubleCell.TYPE.isASuperTypeOf(dataType)) {
                    return new DoubleCell(Double.parseDouble(outcome));
                }
                return new StringCell(outcome);
            } catch (NumberFormatException e) {
                return new MissingCell(outcome + "\n" + e.getMessage());
            }
        }

        /**
         * Selects the first rule that matches and computes the confidence and result for the {@code row}.
         *
         * @param row A {@link DataRow}.
         * @return The result and the confidence.
         */
        private Pair<DataCell, Double> selectFirstHit(final DataRow row) {
            for (final PMMLRuleTranslator.Rule rule : rules) {
                Boolean eval = rule.getCondition().evaluate(row, spec);
                if (eval == Boolean.TRUE) {
                    rule.setRecordCount(rule.getRecordCount() + 1);
                    DataCell result = result(rule);
                    if (validationColumnIdx >= 0) {
                        if (row.getCell(validationColumnIdx).equals(result)) {
                            rule.setNbCorrect(rule.getNbCorrect() + 1);
                        }
                    }
                    Double confidence = rule.getConfidence();
                    return pair(result, confidence == null ? defaultConfidence : confidence);
                }
            }
            return pair(result(defaultScore), defaultConfidence);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void afterProcessing() {
            super.afterProcessing();
            obj.getPMMLValue();
            RuleSetModel ruleSet = translator.getOriginalRuleSetModel();
            assert rules.size() == ruleSet.getRuleSet().getSimpleRuleList().size() + ruleSet.getRuleSet().getCompoundRuleList().size();
            if (ruleSet.getRuleSet().getSimpleRuleList().size() == rules.size()) {
                for (int i = 0; i < rules.size(); ++i) {
                    Rule rule = rules.get(i);
                    final SimpleRule simpleRuleArray = ruleSet.getRuleSet().getSimpleRuleArray(i);
                    synchronized (simpleRuleArray) /*synchronized fixes AP-6766 */
                    {
                        simpleRuleArray.setRecordCount(rule.getRecordCount());
                        if (validationColumnIdx >= 0) {
                            simpleRuleArray.setNbCorrect(rule.getNbCorrect());
                        } else if (simpleRuleArray.isSetNbCorrect()) {
                            simpleRuleArray.unsetNbCorrect();
                        }
                    }
                }
            }
        }
    });
    if (replaceColumn) {
        ret.remove(outputColumnName);
        ret.move(ret.getColumnCount() - 1 - (addConfidence ? 1 : 0), oldColumnIndex);
    }
    return ret;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) Node(org.w3c.dom.Node) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell) Entry(java.util.Map.Entry) SimpleRule(org.dmg.pmml.SimpleRuleDocument.SimpleRule) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) BooleanValue(org.knime.core.data.BooleanValue) DataType(org.knime.core.data.DataType) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) Pair(org.knime.core.util.Pair) AbstractCellFactory(org.knime.core.data.container.AbstractCellFactory) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) RuleSelectionMethod(org.dmg.pmml.RuleSelectionMethodDocument.RuleSelectionMethod) Rule(org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator.Rule) LongCell(org.knime.core.data.def.LongCell) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) StringCell(org.knime.core.data.def.StringCell) MissingCell(org.knime.core.data.MissingCell) DataCell(org.knime.core.data.DataCell) SimpleRule(org.dmg.pmml.SimpleRuleDocument.SimpleRule) Rule(org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator.Rule) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with RuleSetModel

use of org.dmg.pmml.RuleSetModelDocument.RuleSetModel in project knime-core by knime.

the class PMMLRuleTranslator method exportTo.

/**
 * {@inheritDoc}
 */
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
    m_nameMapper = new DerivedFieldMapper(pmmlDoc);
    PMML pmml = pmmlDoc.getPMML();
    RuleSetModel ruleSetModel = pmml.addNewRuleSetModel();
    PMMLMiningSchemaTranslator.writeMiningSchema(spec, ruleSetModel);
    ruleSetModel.setModelName("RuleSet");
    ruleSetModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
    RuleSet ruleSet = ruleSetModel.addNewRuleSet();
    RuleSelectionMethod ruleSelectionMethod = ruleSet.addNewRuleSelectionMethod();
    RuleSet origRs = m_originalRuleModel == null ? null : m_originalRuleModel.getRuleSet();
    final List<RuleSelectionMethod> origMethods = origRs == null ? Collections.<RuleSelectionMethod>emptyList() : origRs.getRuleSelectionMethodList();
    ruleSelectionMethod.setCriterion(origMethods.isEmpty() ? Criterion.FIRST_HIT : origMethods.get(0).getCriterion());
    if (!Double.isNaN(m_recordCount)) {
        ruleSet.setRecordCount(m_recordCount);
    }
    if (!Double.isNaN(m_nbCorrect)) {
        ruleSet.setNbCorrect(m_nbCorrect);
    }
    if (!Double.isNaN(m_defaultConfidence)) {
        ruleSet.setDefaultConfidence(m_defaultConfidence);
    }
    if (m_defaultScore != null) {
        ruleSet.setDefaultScore(m_defaultScore);
    }
    new DerivedFieldMapper(pmmlDoc);
    addRules(ruleSet, m_rules);
    return RuleSetModel.type;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) PMML(org.dmg.pmml.PMMLDocument.PMML) RuleSelectionMethod(org.dmg.pmml.RuleSelectionMethodDocument.RuleSelectionMethod)

Example 5 with RuleSetModel

use of org.dmg.pmml.RuleSetModelDocument.RuleSetModel in project knime-core by knime.

the class PMMLPortObject method moveGlobalTransformationsToModel.

/**
 * Moves the content of the transformation dictionary to local
 * transformations of the model if a model exists.
 */
public void moveGlobalTransformationsToModel() {
    PMML pmml = m_pmmlDoc.getPMML();
    TransformationDictionary transDict = pmml.getTransformationDictionary();
    if (transDict == null || transDict.getDerivedFieldArray() == null || transDict.getDerivedFieldArray().length == 0) {
        // nothing to be moved
        return;
    }
    DerivedField[] globalDerivedFields = transDict.getDerivedFieldArray();
    LocalTransformations localTrans = null;
    if (pmml.getTreeModelArray().length > 0) {
        TreeModel model = pmml.getTreeModelArray(0);
        localTrans = model.getLocalTransformations();
        if (localTrans == null) {
            localTrans = model.addNewLocalTransformations();
        }
    } else if (pmml.getClusteringModelArray().length > 0) {
        ClusteringModel model = pmml.getClusteringModelArray(0);
        localTrans = model.getLocalTransformations();
        if (localTrans == null) {
            localTrans = model.addNewLocalTransformations();
        }
    } else if (pmml.getNeuralNetworkArray().length > 0) {
        NeuralNetwork model = pmml.getNeuralNetworkArray(0);
        localTrans = model.getLocalTransformations();
        if (localTrans == null) {
            localTrans = model.addNewLocalTransformations();
        }
    } else if (pmml.getSupportVectorMachineModelArray().length > 0) {
        SupportVectorMachineModel model = pmml.getSupportVectorMachineModelArray(0);
        localTrans = model.getLocalTransformations();
        if (localTrans == null) {
            localTrans = model.addNewLocalTransformations();
        }
    } else if (pmml.getRegressionModelArray().length > 0) {
        RegressionModel model = pmml.getRegressionModelArray(0);
        localTrans = model.getLocalTransformations();
        if (localTrans == null) {
            localTrans = model.addNewLocalTransformations();
        }
    } else if (pmml.getGeneralRegressionModelArray().length > 0) {
        GeneralRegressionModel model = pmml.getGeneralRegressionModelArray(0);
        localTrans = model.getLocalTransformations();
        if (localTrans == null) {
            localTrans = model.addNewLocalTransformations();
        }
    } else if (pmml.sizeOfRuleSetModelArray() > 0) {
        RuleSetModel model = pmml.getRuleSetModelArray(0);
        localTrans = model.getLocalTransformations();
        if (localTrans == null) {
            localTrans = model.addNewLocalTransformations();
        }
    }
    if (localTrans != null) {
        DerivedField[] derivedFields = appendDerivedFields(localTrans.getDerivedFieldArray(), globalDerivedFields);
        localTrans.setDerivedFieldArray(derivedFields);
        // remove derived fields from TransformationDictionary
        transDict.setDerivedFieldArray(new DerivedField[0]);
    }
// else do nothing as no model exists yet
}
Also used : TreeModel(org.dmg.pmml.TreeModelDocument.TreeModel) RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) LocalTransformations(org.dmg.pmml.LocalTransformationsDocument.LocalTransformations) TransformationDictionary(org.dmg.pmml.TransformationDictionaryDocument.TransformationDictionary) GeneralRegressionModel(org.dmg.pmml.GeneralRegressionModelDocument.GeneralRegressionModel) PMML(org.dmg.pmml.PMMLDocument.PMML) NeuralNetwork(org.dmg.pmml.NeuralNetworkDocument.NeuralNetwork) SupportVectorMachineModel(org.dmg.pmml.SupportVectorMachineModelDocument.SupportVectorMachineModel) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField) ClusteringModel(org.dmg.pmml.ClusteringModelDocument.ClusteringModel) GeneralRegressionModel(org.dmg.pmml.GeneralRegressionModelDocument.GeneralRegressionModel) RegressionModel(org.dmg.pmml.RegressionModelDocument.RegressionModel)

Aggregations

RuleSetModel (org.dmg.pmml.RuleSetModelDocument.RuleSetModel)11 PMML (org.dmg.pmml.PMMLDocument.PMML)8 RuleSet (org.dmg.pmml.RuleSetDocument.RuleSet)6 ClusteringModel (org.dmg.pmml.ClusteringModelDocument.ClusteringModel)4 GeneralRegressionModel (org.dmg.pmml.GeneralRegressionModelDocument.GeneralRegressionModel)4 NeuralNetwork (org.dmg.pmml.NeuralNetworkDocument.NeuralNetwork)4 PMMLDocument (org.dmg.pmml.PMMLDocument)4 RegressionModel (org.dmg.pmml.RegressionModelDocument.RegressionModel)4 SupportVectorMachineModel (org.dmg.pmml.SupportVectorMachineModelDocument.SupportVectorMachineModel)4 TreeModel (org.dmg.pmml.TreeModelDocument.TreeModel)4 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)4 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)4 NaiveBayesModel (org.dmg.pmml.NaiveBayesModelDocument.NaiveBayesModel)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)3 ParseException (java.text.ParseException)2 AssociationModel (org.dmg.pmml.AssociationModelDocument.AssociationModel)2 LocalTransformations (org.dmg.pmml.LocalTransformationsDocument.LocalTransformations)2 MiningModel (org.dmg.pmml.MiningModelDocument.MiningModel)2 RuleSelectionMethod (org.dmg.pmml.RuleSelectionMethodDocument.RuleSelectionMethod)2 SequenceModel (org.dmg.pmml.SequenceModelDocument.SequenceModel)2