Search in sources :

Example 1 with DerivedFieldMapper

use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper 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 2 with DerivedFieldMapper

use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.

the class PMMLNeuralNetworkTranslator method initializeFrom.

/**
 * {@inheritDoc}
 */
@Override
public void initializeFrom(final PMMLDocument pmmlDoc) {
    m_nameMapper = new DerivedFieldMapper(pmmlDoc);
    NeuralNetwork[] models = pmmlDoc.getPMML().getNeuralNetworkArray();
    if (models.length == 0) {
        throw new IllegalArgumentException("No neural network model" + " provided.");
    } else if (models.length > 1) {
        LOGGER.warn("Multiple neural network models found. " + "Only the first model is considered.");
    }
    NeuralNetwork nnModel = models[0];
    // ------------------------------
    // initiate Neural Input
    initInputLayer(nnModel);
    // -------------------------------
    // initiate Hidden Layer
    initiateHiddenLayers(nnModel);
    // -------------------------------
    // initiate Final Layer
    initiateFinalLayer(nnModel);
    // --------------------------------
    // initiate Neural Outputs
    initiateNeuralOutputs(nnModel);
    // --------------------------------
    // initiate Neural Network properties
    ACTIVATIONFUNCTION.Enum actFunc = nnModel.getActivationFunction();
    NNNORMALIZATIONMETHOD.Enum normMethod = nnModel.getNormalizationMethod();
    if (ACTIVATIONFUNCTION.LOGISTIC != actFunc) {
        LOGGER.error("Only logistic activation function is " + "supported in KNIME MLP.");
    }
    if (NNNORMALIZATIONMETHOD.NONE != normMethod) {
        LOGGER.error("No normalization method is " + "supported in KNIME MLP.");
    }
    MININGFUNCTION.Enum functionName = nnModel.getFunctionName();
    if (MININGFUNCTION.CLASSIFICATION == functionName) {
        m_mlpMethod = MultiLayerPerceptron.CLASSIFICATION_MODE;
    } else if (MININGFUNCTION.REGRESSION == functionName) {
        m_mlpMethod = MultiLayerPerceptron.REGRESSION_MODE;
    }
    if (m_allLayers.size() < 3) {
        throw new IllegalArgumentException("Only neural networks with 3 Layers supported in KNIME MLP.");
    }
    Layer[] allLayers = new Layer[m_allLayers.size()];
    allLayers = m_allLayers.toArray(allLayers);
    m_mlp = new MultiLayerPerceptron(allLayers);
    Architecture myarch = new Architecture(allLayers[0].getPerceptrons().length, allLayers.length - 2, allLayers[1].getPerceptrons().length, allLayers[allLayers.length - 1].getPerceptrons().length);
    m_mlp.setArchitecture(myarch);
    m_mlp.setClassMapping(m_classmap);
    m_mlp.setInputMapping(m_inputmap);
    m_mlp.setMode(m_mlpMethod);
}
Also used : ACTIVATIONFUNCTION(org.dmg.pmml.ACTIVATIONFUNCTION) Architecture(org.knime.base.data.neural.Architecture) NeuralNetwork(org.dmg.pmml.NeuralNetworkDocument.NeuralNetwork) NeuralLayer(org.dmg.pmml.NeuralLayerDocument.NeuralLayer) Layer(org.knime.base.data.neural.Layer) InputLayer(org.knime.base.data.neural.InputLayer) HiddenLayer(org.knime.base.data.neural.HiddenLayer) MultiLayerPerceptron(org.knime.base.data.neural.MultiLayerPerceptron) DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) MININGFUNCTION(org.dmg.pmml.MININGFUNCTION) NNNORMALIZATIONMETHOD(org.dmg.pmml.NNNORMALIZATIONMETHOD)

Example 3 with DerivedFieldMapper

use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.

the class PMMLNeuralNetworkTranslator method exportTo.

/**
 * {@inheritDoc}
 */
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
    m_nameMapper = new DerivedFieldMapper(pmmlDoc);
    NeuralNetwork nnModel = pmmlDoc.getPMML().addNewNeuralNetwork();
    PMMLMiningSchemaTranslator.writeMiningSchema(spec, nnModel);
    if (m_mlp.getMode() == MultiLayerPerceptron.CLASSIFICATION_MODE) {
        nnModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
    } else if (m_mlp.getMode() == MultiLayerPerceptron.REGRESSION_MODE) {
        nnModel.setFunctionName(MININGFUNCTION.REGRESSION);
    }
    nnModel.setAlgorithmName("RProp");
    nnModel.setActivationFunction(ACTIVATIONFUNCTION.LOGISTIC);
    nnModel.setNormalizationMethod(NNNORMALIZATIONMETHOD.NONE);
    nnModel.setWidth(0.0);
    nnModel.setNumberOfLayers(BigInteger.valueOf(m_mlp.getNrLayers() - 1));
    // add input layer
    addInputLayer(nnModel, m_mlp);
    // add hidden & final layers
    for (int i = 1; i < m_mlp.getNrLayers(); i++) {
        addLayer(nnModel, m_mlp, i);
    }
    // add output layer
    addOutputLayer(nnModel, m_mlp, spec);
    return NeuralNetwork.type;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) NeuralNetwork(org.dmg.pmml.NeuralNetworkDocument.NeuralNetwork)

Example 4 with DerivedFieldMapper

use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.

the class CategoryToNumberNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    if (m_settings.getIncludedColumns().length == 0) {
        // nothing to convert, let's return the input table.
        setWarningMessage("No columns selected," + " returning input.");
    }
    BufferedDataTable inData = (BufferedDataTable) inObjects[0];
    DataTableSpec inSpec = (DataTableSpec) inObjects[0].getSpec();
    ColumnRearranger rearranger = createRearranger(inSpec);
    BufferedDataTable outTable = exec.createColumnRearrangeTable(inData, rearranger, exec);
    // the optional PMML in port (can be null)
    PMMLPortObject inPMMLPort = (PMMLPortObject) inObjects[1];
    PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, rearranger.createSpec());
    PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
    for (CategoryToNumberCellFactory factory : m_factories) {
        PMMLMapValuesTranslator trans = new PMMLMapValuesTranslator(factory.getConfig(), new DerivedFieldMapper(inPMMLPort));
        outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
    }
    return new PortObject[] { outTable, outPMMLPort };
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 5 with DerivedFieldMapper

use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.

the class AbstractTreeModelPMMLTranslator method exportTo.

/**
 * {@inheritDoc}
 */
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
    PMML pmml = pmmlDoc.getPMML();
    TreeModelDocument.TreeModel treeModel = pmml.addNewTreeModel();
    AbstractTreeModelExporter<N> exporter = createExporter(new DerivedFieldMapper(pmmlDoc));
    SchemaType st = exporter.writeModelToPMML(treeModel, spec);
    if (exporter.hasWarning()) {
        addWarning(exporter.getWarning());
    }
    return st;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) PMML(org.dmg.pmml.PMMLDocument.PMML) TreeModel(org.dmg.pmml.TreeModelDocument.TreeModel) TreeModelDocument(org.dmg.pmml.TreeModelDocument) SchemaType(org.apache.xmlbeans.SchemaType)

Aggregations

DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)37 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)11 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)11 PMML (org.dmg.pmml.PMMLDocument.PMML)9 DataTableSpec (org.knime.core.data.DataTableSpec)8 DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)7 BufferedDataTable (org.knime.core.node.BufferedDataTable)7 PortObject (org.knime.core.node.port.PortObject)7 ArrayList (java.util.ArrayList)4 NeuralNetwork (org.dmg.pmml.NeuralNetworkDocument.NeuralNetwork)4 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)4 MININGFUNCTION (org.dmg.pmml.MININGFUNCTION)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 DataType (org.knime.core.data.DataType)3 BigInteger (java.math.BigInteger)2 HashMap (java.util.HashMap)2 SchemaType (org.apache.xmlbeans.SchemaType)2 ACTIVATIONFUNCTION (org.dmg.pmml.ACTIVATIONFUNCTION)2 ArrayType (org.dmg.pmml.ArrayType)2 ClusterDocument (org.dmg.pmml.ClusterDocument)2