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