use of org.dmg.pmml.tree.TreeModel in project jpmml-sparkml by jpmml.
the class RandomForestRegressionModelConverter method encodeModel.
@Override
public MiningModel encodeModel(Schema schema) {
RandomForestRegressionModel model = getTransformer();
List<TreeModel> treeModels = TreeModelUtil.encodeDecisionTreeEnsemble(model, schema);
MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel())).setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.AVERAGE, treeModels));
return miningModel;
}
use of org.dmg.pmml.tree.TreeModel in project jpmml-sparkml by jpmml.
the class TreeModelUtil method encodeTreeModel.
public static TreeModel encodeTreeModel(org.apache.spark.ml.tree.Node node, PredicateManager predicateManager, MiningFunction miningFunction, Schema schema) {
Node root = encodeNode(node, predicateManager, Collections.<FieldName, Set<String>>emptyMap(), miningFunction, schema).setPredicate(new True());
TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root).setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);
String compact = TreeModelOptions.COMPACT;
if (compact != null && Boolean.valueOf(compact)) {
Visitor visitor = new TreeModelCompactor();
visitor.applyTo(treeModel);
}
return treeModel;
}
use of org.dmg.pmml.tree.TreeModel in project jpmml-sparkml by jpmml.
the class TreeModelUtil method encodeDecisionTreeEnsemble.
public static <M extends Model<M> & TreeEnsembleModel<T>, T extends Model<T> & DecisionTreeModel> List<TreeModel> encodeDecisionTreeEnsemble(M model, PredicateManager predicateManager, Schema schema) {
Schema segmentSchema = schema.toAnonymousSchema();
List<TreeModel> treeModels = new ArrayList<>();
T[] trees = model.trees();
for (T tree : trees) {
TreeModel treeModel = encodeDecisionTree(tree, predicateManager, segmentSchema);
treeModels.add(treeModel);
}
return treeModels;
}
use of org.dmg.pmml.tree.TreeModel 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);
}
use of org.dmg.pmml.tree.TreeModel in project drools by kiegroup.
the class TreeModelImplementationProviderTest method getKiePMMLModelWithSources.
@Test
public void getKiePMMLModelWithSources() {
TreeModel treeModel = (TreeModel) pmml.getModels().get(0);
final CommonCompilationDTO<TreeModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, treeModel, new HasClassLoaderMock());
final KiePMMLModelWithSources retrieved = PROVIDER.getKiePMMLModelWithSources(compilationDTO);
assertNotNull(retrieved);
final Map<String, String> sourcesMap = retrieved.getSourcesMap();
assertNotNull(sourcesMap);
assertFalse(sourcesMap.isEmpty());
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
final Map<String, Class<?>> compiled = KieMemoryCompiler.compile(sourcesMap, classLoader);
for (Class<?> clazz : compiled.values()) {
assertTrue(clazz instanceof Serializable);
}
} catch (Throwable t) {
fail(t.getMessage());
}
}
Aggregations