Search in sources :

Example 6 with RuleSet

use of org.dmg.pmml.RuleSetDocument.RuleSet in project knime-core by knime.

the class PMMLRuleEditorNodeModel method createRearrangerAndPMMLModel.

private RearrangerAndPMMLModel createRearrangerAndPMMLModel(final DataTableSpec spec) throws ParseException, InvalidSettingsException {
    final PMMLDocument doc = PMMLDocument.Factory.newInstance();
    final PMML pmml = doc.addNewPMML();
    RuleSetModel ruleSetModel = pmml.addNewRuleSetModel();
    RuleSet ruleSet = ruleSetModel.addNewRuleSet();
    PMMLRuleParser parser = new PMMLRuleParser(spec, getAvailableInputFlowVariables());
    ColumnRearranger rearranger = createRearranger(spec, ruleSet, parser);
    PMMLPortObject ret = new PMMLPortObject(createPMMLPortObjectSpec(rearranger.createSpec(), parser.getUsedColumns()));
    // if (inData[1] != null) {
    // PMMLPortObject po = (PMMLPortObject)inData[1];
    // TransformationDictionary dict = TransformationDictionary.Factory.newInstance();
    // dict.setDerivedFieldArray(po.getDerivedFields());
    // ret.addGlobalTransformations(dict);
    // }
    PMMLRuleTranslator modelTranslator = new PMMLRuleTranslator();
    ruleSetModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
    ruleSet.setDefaultConfidence(defaultConfidenceValue());
    PMMLMiningSchemaTranslator.writeMiningSchema(ret.getSpec(), ruleSetModel);
    PMMLDataDictionaryTranslator ddTranslator = new PMMLDataDictionaryTranslator();
    ddTranslator.exportTo(doc, ret.getSpec());
    modelTranslator.initializeFrom(doc);
    ret.addModelTranslater(modelTranslator);
    ret.validate();
    return new RearrangerAndPMMLModel(rearranger, ret);
}
Also used : RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PMML(org.dmg.pmml.PMMLDocument.PMML) PMMLDocument(org.dmg.pmml.PMMLDocument) PMMLDataDictionaryTranslator(org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator)

Example 7 with RuleSet

use of org.dmg.pmml.RuleSetDocument.RuleSet in project knime-core by knime.

the class PMMLRuleEditorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    RuleSet ruleSet = RuleSet.Factory.newInstance();
    PMMLRuleParser parser = new PMMLRuleParser((DataTableSpec) inSpecs[0], getAvailableInputFlowVariables());
    try {
        ColumnRearranger rearranger = createRearranger((DataTableSpec) inSpecs[0], ruleSet, parser);
        PMMLPortObjectSpec portObjectSpec = createPMMLPortObjectSpec(rearranger.createSpec(), Collections.<String>emptyList());
        return new PortObjectSpec[] { rearranger.createSpec(), portObjectSpec };
    } catch (ParseException e) {
        throw new InvalidSettingsException(e);
    }
}
Also used : RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) ParseException(java.text.ParseException)

Example 8 with RuleSet

use of org.dmg.pmml.RuleSetDocument.RuleSet in project knime-core by knime.

the class PMMLRuleTranslator method parseRulesFromModel.

/**
 * From an xml RuleSetModel it parses the {@link Rule}s.
 *
 * @param ruleModel A {@link RuleSetModel}.
 * @return {@link List} of {@link Rule}s.
 */
private List<Rule> parseRulesFromModel(final RuleSetModel ruleModel) {
    RuleSet ruleSet = ruleModel.getRuleSet();
    List<Rule> ret = parseRuleSet(ruleSet);
    return ret;
}
Also used : RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) CompoundRule(org.dmg.pmml.CompoundRuleDocument.CompoundRule) SimpleRule(org.dmg.pmml.SimpleRuleDocument.SimpleRule)

Example 9 with RuleSet

use of org.dmg.pmml.RuleSetDocument.RuleSet in project knime-core by knime.

the class PMMLRuleTranslator method initializeFrom.

/**
 * {@inheritDoc}
 */
@Override
public void initializeFrom(final PMMLDocument pmmlDoc) {
    m_nameMapper = new DerivedFieldMapper(pmmlDoc);
    List<RuleSetModel> models = pmmlDoc.getPMML().getRuleSetModelList();
    if (models.size() == 0) {
        throw new IllegalArgumentException("No treemodel provided.");
    }
    m_originalRuleModel = models.get(0);
    initDataDictionary(pmmlDoc);
    m_rules = parseRulesFromModel(m_originalRuleModel);
    MININGFUNCTION.Enum functionName = m_originalRuleModel.getFunctionName();
    assert functionName == MININGFUNCTION.CLASSIFICATION : functionName;
    m_isScorable = m_originalRuleModel.getIsScorable();
    RuleSet ruleSet = m_originalRuleModel.getRuleSet();
    m_selectionMethodList = ruleSet.getRuleSelectionMethodList();
    m_defaultScore = ruleSet.isSetDefaultScore() ? ruleSet.getDefaultScore() : null;
    m_defaultConfidence = ruleSet.isSetDefaultConfidence() ? ruleSet.getDefaultConfidence() : Double.NaN;
    m_recordCount = ruleSet.isSetRecordCount() ? ruleSet.getRecordCount() : Double.NaN;
    m_nbCorrect = ruleSet.isSetNbCorrect() ? ruleSet.getNbCorrect() : Double.NaN;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) MININGFUNCTION(org.dmg.pmml.MININGFUNCTION)

Aggregations

RuleSet (org.dmg.pmml.RuleSetDocument.RuleSet)9 RuleSetModel (org.dmg.pmml.RuleSetModelDocument.RuleSetModel)7 PMML (org.dmg.pmml.PMMLDocument.PMML)6 PMMLDocument (org.dmg.pmml.PMMLDocument)5 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)5 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)4 ParseException (java.text.ParseException)3 SimpleRule (org.dmg.pmml.SimpleRuleDocument.SimpleRule)3 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)3 PortObject (org.knime.core.node.port.PortObject)3 PMMLDataDictionaryTranslator (org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator)3 ArrayList (java.util.ArrayList)2 MININGFUNCTION (org.dmg.pmml.MININGFUNCTION)2 PMMLDecisionTreeTranslator (org.knime.base.node.mine.decisiontree2.PMMLDecisionTreeTranslator)2 PMMLPredicate (org.knime.base.node.mine.decisiontree2.PMMLPredicate)2 DecisionTree (org.knime.base.node.mine.decisiontree2.model.DecisionTree)2 DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)2 DecisionTreeNodeSplitPMML (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML)2 RuleSetToTable (org.knime.base.node.rules.engine.totable.RuleSetToTable)2 ExecutionContext (org.knime.core.node.ExecutionContext)2