@Override public List<OutputField> registerOutputFields(Label label, SparkMLEncoder encoder){ MultilayerPerceptronClassificationModel model = getTransformer(); List<OutputField> result = super.registerOutputFields(label, encoder); if(!(model instanceof HasProbabilityCol)){ CategoricalLabel categoricalLabel = (CategoricalLabel)label; result = new ArrayList<>(result); result.addAll(ModelUtil.createProbabilityFields(DataType.DOUBLE, categoricalLabel.getValues())); } return result; }
@Override public List<OutputField> registerOutputFields(Label label, SparkMLEncoder encoder){ List<OutputField> result = super.registerOutputFields(label, encoder); MiningFunction miningFunction = getMiningFunction(); switch(miningFunction){ case CLASSIFICATION: CategoricalLabel categoricalLabel = (CategoricalLabel)label; result = new ArrayList<>(result); result.addAll(ModelUtil.createProbabilityFields(DataType.DOUBLE, categoricalLabel.getValues())); break; default: break; } return result; }
List<String> categories = categoricalLabel.getValues();
MapValues mapValues = PMMLUtil.createMapValues(pmmlPredictedField.getName(), categoricalLabel.getValues(), categories);
CategoricalLabel categoricalLabel = (CategoricalLabel)label; List<String> values = categoricalLabel.getValues();
CategoricalLabel categoricalLabel = (CategoricalLabel)label; List<OutputField> predictProbaFields = ModelUtil.createProbabilityFields(DataType.DOUBLE, categoricalLabel.getValues()); List<String> values = categoricalLabel.getValues(); for(String value : values){ probabilityFields.add("probability(" + value + ")"); // XXX
@Override public NaiveBayesModel encodeModel(Schema schema){ int[] shape = getThetaShape(); int numberOfClasses = shape[0]; int numberOfFeatures = shape[1]; List<? extends Number> theta = getTheta(); List<? extends Number> sigma = getSigma(); CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel(); BayesInputs bayesInputs = new BayesInputs(); for(int i = 0; i < numberOfFeatures; i++){ Feature feature = schema.getFeature(i); List<? extends Number> means = CMatrixUtil.getColumn(theta, numberOfClasses, numberOfFeatures, i); List<? extends Number> variances = CMatrixUtil.getColumn(sigma, numberOfClasses, numberOfFeatures, i); ContinuousFeature continuousFeature = feature.toContinuousFeature(); BayesInput bayesInput = new BayesInput(continuousFeature.getName()) .setTargetValueStats(encodeTargetValueStats(categoricalLabel.getValues(), means, variances)); bayesInputs.addBayesInputs(bayesInput); } List<Integer> classCount = getClassCount(); BayesOutput bayesOutput = new BayesOutput(categoricalLabel.getName(), null) .setTargetValueCounts(encodeTargetValueCounts(categoricalLabel.getValues(), classCount)); NaiveBayesModel naiveBayesModel = new NaiveBayesModel(0d, MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), bayesInputs, bayesOutput) .setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, categoricalLabel)); return naiveBayesModel; }