use of org.dmg.pmml.mining.MiningModel in project jpmml-sparkml by jpmml.
the class ModelConverter method getLastModel.
protected org.dmg.pmml.Model getLastModel(org.dmg.pmml.Model model) {
if (model instanceof MiningModel) {
MiningModel miningModel = (MiningModel) model;
Segmentation segmentation = miningModel.getSegmentation();
MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
switch(multipleModelMethod) {
case MODEL_CHAIN:
List<Segment> segments = segmentation.getSegments();
if (segments.size() > 0) {
Segment lastSegment = segments.get(segments.size() - 1);
return lastSegment.getModel();
}
break;
default:
break;
}
}
return model;
}
use of org.dmg.pmml.mining.MiningModel in project jpmml-sparkml by jpmml.
the class GBTClassificationModelConverter method encodeModel.
@Override
public MiningModel encodeModel(Schema schema) {
GBTClassificationModel model = getTransformer();
String lossType = model.getLossType();
switch(lossType) {
case "logistic":
break;
default:
throw new IllegalArgumentException("Loss function " + lossType + " is not supported");
}
Schema segmentSchema = new Schema(new ContinuousLabel(null, DataType.DOUBLE), schema.getFeatures());
List<TreeModel> treeModels = TreeModelUtil.encodeDecisionTreeEnsemble(model, segmentSchema);
MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(segmentSchema.getLabel())).setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.WEIGHTED_SUM, treeModels, Doubles.asList(model.treeWeights()))).setOutput(ModelUtil.createPredictedOutput(FieldName.create("gbtValue"), OpType.CONTINUOUS, DataType.DOUBLE));
return MiningModelUtil.createBinaryLogisticClassification(miningModel, 2d, 0d, RegressionModel.NormalizationMethod.LOGIT, false, schema);
}
Aggregations