use of org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator 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) };
}
use of org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator in project knime-core by knime.
the class AbstractMetaDataMapper method extractTableSpecFromPMMLDoc.
private static DataTableSpec extractTableSpecFromPMMLDoc(final PMMLDocument pmmlDoc) {
PMMLDataDictionaryTranslator dataDictTrans = new PMMLDataDictionaryTranslator();
dataDictTrans.initializeFrom(pmmlDoc);
return dataDictTrans.getDataTableSpec();
}
use of org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator in project knime-core by knime.
the class PMMLImport method init.
/**
* @param pmmlDoc
*/
private void init(final PMMLDocument pmmlDoc) {
PMMLDataDictionaryTranslator dictTrans = new PMMLDataDictionaryTranslator();
dictTrans.initializeFrom(pmmlDoc);
DataTableSpec tableSpec = dictTrans.getDataTableSpec();
List<String> activeDerivedFields = dictTrans.getActiveDerivedFields();
PMMLPortObjectSpecCreator specCreator = new PMMLPortObjectSpecCreator(tableSpec);
PMMLMiningSchemaTranslator miningTrans = new PMMLMiningSchemaTranslator();
miningTrans.initializeFrom(pmmlDoc);
Set<String> activeFields = new LinkedHashSet<String>();
List<String> miningFields = miningTrans.getActiveFields();
/* If we have a model all active fields of the data dictionary
* are passed through the mining schema. */
activeFields.addAll(miningFields);
activeFields.addAll(activeDerivedFields);
specCreator.setLearningColsNames(new LinkedList<String>(activeFields));
specCreator.addPreprocColNames(activeDerivedFields);
specCreator.setTargetColsNames(miningTrans.getTargetFields());
PMMLPortObjectSpec portObjectSpec = specCreator.createSpec();
m_portObject = new PMMLPortObject(portObjectSpec, pmmlDoc);
}
use of org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator in project knime-core by knime.
the class RuleEngine2PortsNodeModel method fillUsingDoc.
/**
* Fills the results obtained from {@code doc}.
*
* @param doc A {@link PMMLDocument}.
* @param ruleSetModel The {@link RuleSetModel}.
* @param pmml The {@link PMMLPortObject}.
*/
private void fillUsingDoc(final PMMLDocument doc, final RuleSetModel ruleSetModel, final PMMLPortObject pmml) {
PMMLRuleTranslator modelTranslator = new PMMLRuleTranslator(m_settings.isProvideStatistics());
PMMLMiningSchemaTranslator.writeMiningSchema(pmml.getSpec(), ruleSetModel);
PMMLDataDictionaryTranslator ddTranslator = new PMMLDataDictionaryTranslator();
ddTranslator.exportTo(doc, pmml.getSpec());
modelTranslator.initializeFrom(doc);
pmml.addModelTranslater(modelTranslator);
pmml.validate();
}
use of org.knime.core.node.port.pmml.PMMLDataDictionaryTranslator 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);
}
Aggregations