use of org.jpmml.converter.CategoricalLabel in project jpmml-r by jpmml.
the class LRMConverter method encodeModel.
@Override
public Model encodeModel(Schema schema) {
RGenericVector lrm = getObject();
RDoubleVector coefficients = lrm.getDoubleElement("coefficients");
CategoricalLabel categoricalLabel = (CategoricalLabel) schema.getLabel();
SchemaUtil.checkSize(2, categoricalLabel);
Object targetCategory = categoricalLabel.getValue(1);
Double intercept = coefficients.getElement(getInterceptName(), false);
List<? extends Feature> features = schema.getFeatures();
SchemaUtil.checkSize(coefficients.size() - (intercept != null ? 1 : 0), features);
List<Double> featureCoefficients = getFeatureCoefficients(features, coefficients);
GeneralRegressionModel generalRegressionModel = new GeneralRegressionModel(GeneralRegressionModel.ModelType.GENERALIZED_LINEAR, MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), null, null, null).setLinkFunction(GeneralRegressionModel.LinkFunction.LOGIT).setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, categoricalLabel));
GeneralRegressionModelUtil.encodeRegressionTable(generalRegressionModel, features, featureCoefficients, intercept, targetCategory);
return generalRegressionModel;
}
use of org.jpmml.converter.CategoricalLabel in project jpmml-r by jpmml.
the class BoostingConverter method encodeModel.
@Override
public Model encodeModel(Schema schema) {
RGenericVector boosting = getObject();
RGenericVector trees = boosting.getGenericElement("trees");
RDoubleVector weights = boosting.getDoubleElement("weights");
CategoricalLabel categoricalLabel = (CategoricalLabel) schema.getLabel();
List<TreeModel> treeModels = encodeTreeModels(trees);
MiningModel miningModel = new MiningModel(MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel)).setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.WEIGHTED_MAJORITY_VOTE, treeModels, weights.getValues())).setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, categoricalLabel));
return miningModel;
}
use of org.jpmml.converter.CategoricalLabel in project jpmml-r by jpmml.
the class BinaryTreeConverter method encodeClassificationScore.
private static Node encodeClassificationScore(Node node, RDoubleVector probabilities, Schema schema) {
CategoricalLabel categoricalLabel = (CategoricalLabel) schema.getLabel();
SchemaUtil.checkSize(probabilities.size(), categoricalLabel);
node = new ClassifierNode(node);
List<ScoreDistribution> scoreDistributions = node.getScoreDistributions();
Double maxProbability = null;
for (int i = 0; i < categoricalLabel.size(); i++) {
Object value = categoricalLabel.getValue(i);
Double probability = probabilities.getValue(i);
if (maxProbability == null || (maxProbability).compareTo(probability) < 0) {
node.setScore(value);
maxProbability = probability;
}
ScoreDistribution scoreDistribution = new ScoreDistribution(value, probability);
scoreDistributions.add(scoreDistribution);
}
return node;
}
Aggregations