org.dmg.pmml.tree.ClassifierNode Java Examples
The following examples show how to use
org.dmg.pmml.tree.ClassifierNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DummyClassifier.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 4 votes |
@Override public TreeModel encodeModel(Schema schema){ List<?> classes = getClasses(); List<? extends Number> classPrior = getClassPrior(); Object constant = getConstant(); String strategy = getStrategy(); ClassDictUtil.checkSize(classes, classPrior); CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel(); int index; double[] probabilities; switch(strategy){ case "constant": { index = classes.indexOf(constant); probabilities = new double[classes.size()]; probabilities[index] = 1d; } break; case "most_frequent": { index = classPrior.indexOf(Collections.max((List)classPrior)); probabilities = new double[classes.size()]; probabilities[index] = 1d; } break; case "prior": { index = classPrior.indexOf(Collections.max((List)classPrior)); probabilities = Doubles.toArray(classPrior); } break; default: throw new IllegalArgumentException(strategy); } Node root = new ClassifierNode(ValueUtil.asString(classes.get(index)), True.INSTANCE); List<ScoreDistribution> scoreDistributions = root.getScoreDistributions(); for(int i = 0; i < classes.size(); i++){ ScoreDistribution scoreDistribution = new ScoreDistribution(ValueUtil.asString(classes.get(i)), probabilities[i]); scoreDistributions.add(scoreDistribution); } TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), root) .setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, categoricalLabel)); return treeModel; }