Search in sources :

Example 16 with PMML

use of org.dmg.pmml.PMMLDocument.PMML in project knime-core by knime.

the class TreeModelPMMLTranslator method exportTo.

/**
 * {@inheritDoc}
 */
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
    PMML pmml = pmmlDoc.getPMML();
    TreeModelDocument.TreeModel treeModel = pmml.addNewTreeModel();
    PMMLMiningSchemaTranslator.writeMiningSchema(spec, treeModel);
    treeModel.setModelName("DecisionTree");
    treeModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
    TreeNodeClassification rootNode = m_treeModel.getRootNode();
    // set up splitCharacteristic
    if (isMultiSplitRecursive(rootNode)) {
        treeModel.setSplitCharacteristic(SplitCharacteristic.MULTI_SPLIT);
    } else {
        treeModel.setSplitCharacteristic(SplitCharacteristic.BINARY_SPLIT);
    }
    // ----------------------------------------------
    // set up missing value strategy
    treeModel.setMissingValueStrategy(MISSINGVALUESTRATEGY.NONE);
    // -------------------------------------------------
    // set up no true child strategy
    treeModel.setNoTrueChildStrategy(NOTRUECHILDSTRATEGY.RETURN_LAST_PREDICTION);
    // --------------------------------------------------
    // set up tree node
    NodeDocument.Node rootPMMLNode = treeModel.addNewNode();
    addTreeNode(rootPMMLNode, rootNode);
    return TreeModelDocument.TreeModel.type;
}
Also used : Node(org.dmg.pmml.NodeDocument.Node) PMML(org.dmg.pmml.PMMLDocument.PMML) NodeDocument(org.dmg.pmml.NodeDocument) TreeModelDocument(org.dmg.pmml.TreeModelDocument)

Example 17 with PMML

use of org.dmg.pmml.PMMLDocument.PMML in project knime-core by knime.

the class PMMLUtils method getFirstMiningSchema.

/**
 * Retrieves the mining schema of the first model of a specific type.
 *
 * @param pmmlDoc the PMML document to extract the mining schema from
 * @param type the type of the model
 * @return the mining schema of the first model of the given type or null if
 *         there is no model of the given type contained in the pmmlDoc
 */
public static MiningSchema getFirstMiningSchema(final PMMLDocument pmmlDoc, final SchemaType type) {
    Map<PMMLModelType, Integer> models = getNumberOfModels(pmmlDoc);
    if (!models.containsKey(PMMLModelType.getType(type))) {
        return null;
    }
    PMML pmml = pmmlDoc.getPMML();
    /*
         * Unfortunately the PMML models have no common base class. Therefore a
         * cast to the specific type is necessary for being able to add the
         * mining schema.
         */
    if (AssociationModel.type.equals(type)) {
        AssociationModel model = pmml.getAssociationModelArray(0);
        return model.getMiningSchema();
    } else if (ClusteringModel.type.equals(type)) {
        ClusteringModel model = pmml.getClusteringModelArray(0);
        return model.getMiningSchema();
    } else if (GeneralRegressionModel.type.equals(type)) {
        GeneralRegressionModel model = pmml.getGeneralRegressionModelArray(0);
        return model.getMiningSchema();
    } else if (MiningModel.type.equals(type)) {
        MiningModel model = pmml.getMiningModelArray(0);
        return model.getMiningSchema();
    } else if (NaiveBayesModel.type.equals(type)) {
        NaiveBayesModel model = pmml.getNaiveBayesModelArray(0);
        return model.getMiningSchema();
    } else if (NeuralNetwork.type.equals(type)) {
        NeuralNetwork model = pmml.getNeuralNetworkArray(0);
        return model.getMiningSchema();
    } else if (RegressionModel.type.equals(type)) {
        RegressionModel model = pmml.getRegressionModelArray(0);
        return model.getMiningSchema();
    } else if (RuleSetModel.type.equals(type)) {
        RuleSetModel model = pmml.getRuleSetModelArray(0);
        return model.getMiningSchema();
    } else if (SequenceModel.type.equals(type)) {
        SequenceModel model = pmml.getSequenceModelArray(0);
        return model.getMiningSchema();
    } else if (SupportVectorMachineModel.type.equals(type)) {
        SupportVectorMachineModel model = pmml.getSupportVectorMachineModelArray(0);
        return model.getMiningSchema();
    } else if (TextModel.type.equals(type)) {
        TextModel model = pmml.getTextModelArray(0);
        return model.getMiningSchema();
    } else if (TimeSeriesModel.type.equals(type)) {
        TimeSeriesModel model = pmml.getTimeSeriesModelArray(0);
        return model.getMiningSchema();
    } else if (TreeModel.type.equals(type)) {
        TreeModel model = pmml.getTreeModelArray(0);
        return model.getMiningSchema();
    } else {
        return null;
    }
}
Also used : RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) SequenceModel(org.dmg.pmml.SequenceModelDocument.SequenceModel) TextModel(org.dmg.pmml.TextModelDocument.TextModel) NaiveBayesModel(org.dmg.pmml.NaiveBayesModelDocument.NaiveBayesModel) TimeSeriesModel(org.dmg.pmml.TimeSeriesModelDocument.TimeSeriesModel) NeuralNetwork(org.dmg.pmml.NeuralNetworkDocument.NeuralNetwork) RegressionModel(org.dmg.pmml.RegressionModelDocument.RegressionModel) GeneralRegressionModel(org.dmg.pmml.GeneralRegressionModelDocument.GeneralRegressionModel) TreeModel(org.dmg.pmml.TreeModelDocument.TreeModel) MiningModel(org.dmg.pmml.MiningModelDocument.MiningModel) GeneralRegressionModel(org.dmg.pmml.GeneralRegressionModelDocument.GeneralRegressionModel) PMML(org.dmg.pmml.PMMLDocument.PMML) SupportVectorMachineModel(org.dmg.pmml.SupportVectorMachineModelDocument.SupportVectorMachineModel) AssociationModel(org.dmg.pmml.AssociationModelDocument.AssociationModel) ClusteringModel(org.dmg.pmml.ClusteringModelDocument.ClusteringModel)

Example 18 with PMML

use of org.dmg.pmml.PMMLDocument.PMML in project knime-core by knime.

the class PMMLUtils method getNumberOfModels.

/**
 * @param pmmlDoc the PMML document to retrieve the model information for
 * @return a map containing the number of contained models for each PMML
 *         model type
 */
public static Map<PMMLModelType, Integer> getNumberOfModels(final PMMLDocument pmmlDoc) {
    Map<PMMLModelType, Integer> numModels = new LinkedHashMap<PMMLModelType, Integer>();
    PMML pmml = pmmlDoc.getPMML();
    int num = pmml.sizeOfAssociationModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.AssociationModel, num);
    }
    num = pmml.sizeOfClusteringModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.ClusteringModel, num);
    }
    num = pmml.sizeOfGeneralRegressionModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.GeneralRegressionModel, num);
    }
    num = pmml.sizeOfMiningModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.MiningModel, num);
    }
    num = pmml.sizeOfNaiveBayesModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.NaiveBayesModel, num);
    }
    num = pmml.sizeOfNeuralNetworkArray();
    if (num > 0) {
        numModels.put(PMMLModelType.NeuralNetwork, num);
    }
    num = pmml.sizeOfRegressionModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.RegressionModel, num);
    }
    num = pmml.sizeOfRuleSetModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.RuleSetModel, num);
    }
    num = pmml.sizeOfSequenceModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.SequenceModel, num);
    }
    num = pmml.sizeOfSupportVectorMachineModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.SupportVectorMachineModel, num);
    }
    num = pmml.sizeOfTextModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.TextModel, num);
    }
    num = pmml.sizeOfTimeSeriesModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.TimeSeriesModel, num);
    }
    num = pmml.sizeOfTreeModelArray();
    if (num > 0) {
        numModels.put(PMMLModelType.TreeModel, num);
    }
    return numModels;
}
Also used : PMML(org.dmg.pmml.PMMLDocument.PMML) LinkedHashMap(java.util.LinkedHashMap)

Example 19 with PMML

use of org.dmg.pmml.PMMLDocument.PMML in project knime-core by knime.

the class PMMLSVMTranslator method exportTo.

/**
 * {@inheritDoc}
 */
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
    m_nameMapper = new DerivedFieldMapper(pmmlDoc);
    PMML pmml = pmmlDoc.getPMML();
    SupportVectorMachineModel svmModel = pmml.addNewSupportVectorMachineModel();
    PMMLMiningSchemaTranslator.writeMiningSchema(spec, svmModel);
    // add support vector machine model attributes
    svmModel.setModelName("SVM");
    svmModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
    svmModel.setAlgorithmName("Sequential Minimal Optimization (SMO)");
    svmModel.setSvmRepresentation(SVMREPRESENTATION.SUPPORT_VECTORS);
    addTargets(svmModel, spec.getTargetFields().get(0));
    addKernel(svmModel);
    addVectorDictionary(svmModel, spec.getLearningFields());
    addSVMs(svmModel);
    return SupportVectorMachineModel.type;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) PMML(org.dmg.pmml.PMMLDocument.PMML) SupportVectorMachineModel(org.dmg.pmml.SupportVectorMachineModelDocument.SupportVectorMachineModel)

Example 20 with PMML

use of org.dmg.pmml.PMMLDocument.PMML in project knime-core by knime.

the class PMMLNaiveBayesModelTranslator method exportTo.

/**
 * {@inheritDoc}
 */
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
    if (m_model == null) {
        throw new NullPointerException("No model found to serialize");
    }
    DerivedFieldMapper mapper = new DerivedFieldMapper(pmmlDoc);
    final PMML pmml = pmmlDoc.getPMML();
    final org.dmg.pmml.NaiveBayesModelDocument.NaiveBayesModel bayesModel = pmml.addNewNaiveBayesModel();
    PMMLMiningSchemaTranslator.writeMiningSchema(spec, bayesModel);
    m_model.exportToPMML(bayesModel, mapper);
    return org.dmg.pmml.NaiveBayesModelDocument.NaiveBayesModel.type;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) PMML(org.dmg.pmml.PMMLDocument.PMML)

Aggregations

PMML (org.dmg.pmml.PMMLDocument.PMML)27 RuleSetModel (org.dmg.pmml.RuleSetModelDocument.RuleSetModel)9 DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)9 PMMLDocument (org.dmg.pmml.PMMLDocument)8 RuleSet (org.dmg.pmml.RuleSetDocument.RuleSet)6 TreeModel (org.dmg.pmml.TreeModelDocument.TreeModel)6 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)6 ClusteringModel (org.dmg.pmml.ClusteringModelDocument.ClusteringModel)5 ArrayList (java.util.ArrayList)4 DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)3 MiningModel (org.dmg.pmml.MiningModelDocument.MiningModel)3 NodeDocument (org.dmg.pmml.NodeDocument)3 Node (org.dmg.pmml.NodeDocument.Node)3 SupportVectorMachineModel (org.dmg.pmml.SupportVectorMachineModelDocument.SupportVectorMachineModel)3 TreeModelDocument (org.dmg.pmml.TreeModelDocument)3 DecisionTreeNodeSplitPMML (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML)3 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 ParseException (java.text.ParseException)2 LinkedHashMap (java.util.LinkedHashMap)2