Search in sources :

Example 1 with Extension

use of org.dmg.pmml.ExtensionDocument.Extension in project knime-core by knime.

the class GBTRegressionTreeModelExporter method addExtension.

/**
 * {@inheritDoc}
 */
@Override
protected void addExtension(final Node pmmlNode, final TreeNodeRegression node) {
    super.addExtension(pmmlNode, node);
    // store the gbt coefficient for leafs
    if (node.getNrChildren() == 0) {
        Extension ext = pmmlNode.addNewExtension();
        ext.setName(TranslationUtil.MEAN_KEY);
        CheckUtils.checkArgument(m_coefficientMap.containsKey(node.getSignature()), "The GBT model contains no coefficient for the leaf %s.", node);
        ext.setValue(Double.toString(node.getMean()));
    }
}
Also used : Extension(org.dmg.pmml.ExtensionDocument.Extension)

Example 2 with Extension

use of org.dmg.pmml.ExtensionDocument.Extension in project knime-core by knime.

the class RegressionTreeModelExporter method addExtension.

protected void addExtension(final Node pmmlNode, final TreeNodeRegression node) {
    Extension ext = pmmlNode.addNewExtension();
    ext.setName(TranslationUtil.SUM_SQUARED_DEVIATION_KEY);
    ext.setValue(Double.toString(node.getSumSquaredDeviation()));
    ext = pmmlNode.addNewExtension();
    ext.setName(TranslationUtil.TOTAL_SUM_KEY);
    ext.setValue(Double.toString(node.getTotalSum()));
}
Also used : Extension(org.dmg.pmml.ExtensionDocument.Extension)

Example 3 with Extension

use of org.dmg.pmml.ExtensionDocument.Extension in project knime-core by knime.

the class PMMLNormalizeTranslator method createSummaryExtension.

private Extension[] createSummaryExtension() {
    Extension extension = Extension.Factory.newInstance();
    extension.setName(SUMMARY);
    extension.setExtender(PMMLPortObjectSpec.KNIME);
    extension.setValue(m_affineTrans.getSummary());
    return new Extension[] { extension };
}
Also used : Extension(org.dmg.pmml.ExtensionDocument.Extension)

Example 4 with Extension

use of org.dmg.pmml.ExtensionDocument.Extension in project knime-core by knime.

the class PMMLMapValuesTranslator method createSummaryExtension.

private Extension[] createSummaryExtension() {
    Extension extension = Extension.Factory.newInstance();
    extension.setName("summary");
    extension.setExtender(PMMLPortObjectSpec.KNIME);
    extension.setValue(m_config.getSummary());
    return new Extension[] { extension };
}
Also used : Extension(org.dmg.pmml.ExtensionDocument.Extension)

Example 5 with Extension

use of org.dmg.pmml.ExtensionDocument.Extension in project knime-core by knime.

the class MissingCellHandler method createExtensionDerivedField.

/**
 * Creates a derived field that contains an extension which
 * contains the name of the factory to use for the replacement.
 * The result may be adjusted to contain necessary information for the handler.
 * @param dataType the data type of the derived field
 * @param factoryID the id of the factory
 * @return the derived field
 */
protected DerivedField createExtensionDerivedField(final DATATYPE.Enum dataType, final String factoryID) {
    DerivedField field = DerivedField.Factory.newInstance();
    if (dataType == org.dmg.pmml.DATATYPE.STRING || dataType == org.dmg.pmml.DATATYPE.BOOLEAN) {
        field.setOptype(org.dmg.pmml.OPTYPE.CATEGORICAL);
    } else {
        field.setOptype(org.dmg.pmml.OPTYPE.CONTINUOUS);
    }
    Extension e = field.addNewExtension();
    e.setName(CUSTOM_HANDLER_EXTENSION_NAME);
    e.setValue(factoryID);
    field.setDataType(dataType);
    field.setName(m_col.getName());
    field.setDisplayName(m_col.getName());
    // Insert settings
    NodeSettings nodeSettings = new NodeSettings("");
    saveSettingsTo(nodeSettings);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        nodeSettings.saveToXML(baos);
        Document doc = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray()));
        Node copy = e.getDomNode().getOwnerDocument().importNode(doc.getFirstChild(), true);
        e.getDomNode().appendChild(copy);
    } catch (Exception ex) {
        LOGGER.error("An error occurred while writing settings to PMML.\n" + ex.getMessage());
        return null;
    }
    return field;
}
Also used : Extension(org.dmg.pmml.ExtensionDocument.Extension) NodeSettings(org.knime.core.node.NodeSettings) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(org.w3c.dom.Node) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Aggregations

Extension (org.dmg.pmml.ExtensionDocument.Extension)6 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeSettings (org.knime.core.node.NodeSettings)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1