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);
}
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);
}
}
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;
}
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;
}
Aggregations