org.dmg.pmml.tree.TreeModel Java Examples

The following examples show how to use org.dmg.pmml.tree.TreeModel. 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: TreeModelUtil.java    From jpmml-sparkml with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public <C extends ModelConverter<? extends M> & HasTreeOptions, M extends Model<M> & TreeEnsembleModel<T>, T extends Model<T> & DecisionTreeModel> List<TreeModel> encodeDecisionTreeEnsemble(C converter, PredicateManager predicateManager, Schema schema){
	M model = converter.getTransformer();

	Schema segmentSchema = schema.toAnonymousSchema();

	List<TreeModel> treeModels = new ArrayList<>();

	T[] trees = model.trees();
	for(T tree : trees){
		TreeModel treeModel = encodeDecisionTree(converter, tree, predicateManager, segmentSchema);

		treeModels.add(treeModel);
	}

	return treeModels;
}
 
Example #2
Source File: RPartConverter.java    From jpmml-r with GNU Affero General Public License v3.0 6 votes vote down vote up
private TreeModel encodeRegression(RGenericVector frame, RIntegerVector rowNames, RIntegerVector var, RIntegerVector n, int[][] splitInfo, RNumberVector<?> splits, RIntegerVector csplit, Schema schema){
	RNumberVector<?> yval = frame.getNumericElement("yval");

	ScoreEncoder scoreEncoder = new ScoreEncoder(){

		@Override
		public Node encode(Node node, int offset){
			Number score = yval.getValue(offset);
			Number recordCount = n.getValue(offset);

			node
				.setScore(score)
				.setRecordCount(recordCount);

			return node;
		}
	};

	Node root = encodeNode(True.INSTANCE, 1, rowNames, var, n, splitInfo, splits, csplit, scoreEncoder, schema);

	TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), root);

	return configureTreeModel(treeModel);
}
 
Example #3
Source File: BoostingConverter.java    From jpmml-r with GNU Affero General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: RPartConverter.java    From jpmml-r with GNU Affero General Public License v3.0 6 votes vote down vote up
private TreeModel configureTreeModel(TreeModel treeModel){
	TreeModel.NoTrueChildStrategy noTrueChildStrategy = TreeModel.NoTrueChildStrategy.RETURN_LAST_PREDICTION;
	TreeModel.MissingValueStrategy missingValueStrategy;

	switch(this.useSurrogate){
		case 0:
			missingValueStrategy = TreeModel.MissingValueStrategy.NULL_PREDICTION; // XXX
			break;
		case 1:
			missingValueStrategy = TreeModel.MissingValueStrategy.LAST_PREDICTION;
			break;
		case 2:
			missingValueStrategy = null;
			break;
		default:
			throw new IllegalArgumentException();
	}

	treeModel
		.setNoTrueChildStrategy(noTrueChildStrategy)
		.setMissingValueStrategy(missingValueStrategy);

	return treeModel;
}
 
Example #5
Source File: TargetCategoryParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(Node node){
	PMMLObject parent = getParent();

	if(parent instanceof TreeModel){
		TreeModel treeModel = (TreeModel)parent;

		MiningFunction miningFunction = treeModel.getMiningFunction();
		switch(miningFunction){
			case CLASSIFICATION:
				break;
			default:
				return VisitorAction.SKIP;
		}
	}

	node.setScore(parseTargetValue(node.getScore()));

	return super.visit(node);
}
 
Example #6
Source File: RandomForestConverter.java    From jpmml-r with GNU Affero General Public License v3.0 6 votes vote down vote up
private <P extends Number> TreeModel encodeTreeModel(MiningFunction miningFunction, ScoreEncoder<P> scoreEncoder, List<? extends Number> leftDaughter, List<? extends Number> rightDaughter, List<P> nodepred, List<? extends Number> bestvar, List<Double> xbestsplit, Schema schema){
	RGenericVector randomForest = getObject();

	Node root = encodeNode(True.INSTANCE, 0, scoreEncoder, leftDaughter, rightDaughter, bestvar, xbestsplit, nodepred, new CategoryManager(), schema);

	TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root)
		.setMissingValueStrategy(TreeModel.MissingValueStrategy.NULL_PREDICTION)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);

	if(this.compact){
		Visitor visitor = new RandomForestCompactor();

		visitor.applyTo(treeModel);
	}

	return treeModel;
}
 
Example #7
Source File: RPartEnsembleConverter.java    From jpmml-r with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<TreeModel> encodeTreeModels(RGenericVector trees){
	List<TreeModel> result = new ArrayList<>();

	if(trees.size() != this.schemas.size()){
		throw new IllegalArgumentException();
	}

	for(int i = 0; i < trees.size(); i++){
		RGenericVector tree = (RGenericVector)trees.getValue(i);
		Schema schema = this.schemas.get(i);

		RPartConverter converter = this.converters.get(tree);
		if(converter == null){
			throw new IllegalArgumentException();
		}

		Schema segmentSchema = schema.toAnonymousSchema();

		TreeModel treeModel = converter.encodeModel(segmentSchema);

		result.add(treeModel);
	}

	return result;
}
 
Example #8
Source File: MissingValueStrategyTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void defaultChildMultiplePenalties() throws Exception {
	Map<FieldName, ?> arguments = createArguments("outlook", null, "temperature", null, "humidity", 70d);

	NodeScoreDistribution<?> targetValue = evaluate(TreeModel.MissingValueStrategy.DEFAULT_CHILD, 0.8d, arguments);

	assertEquals("3", targetValue.getEntityId());

	assertEquals((Double)0.9d, targetValue.getProbability("will play"));
	assertEquals((Double)0.05d, targetValue.getProbability("may play"));
	assertEquals((Double)0.05d, targetValue.getProbability("no play"));

	double missingValuePenalty = (0.8d * 0.8d);

	assertEquals((Double)(0.9d * missingValuePenalty), targetValue.getConfidence("will play"));
	assertEquals((Double)(0.05d * missingValuePenalty), targetValue.getConfidence("may play"));
	assertEquals((Double)(0.05d * missingValuePenalty), targetValue.getConfidence("no play"));
}
 
Example #9
Source File: TreeModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @param parent The parent Node of the Node that evaluated to the missing value.
 * @param node The Node that evaluated to the missing value.
 */
private Trail handleMissingValue(Trail trail, Node parent, Node node, EvaluationContext context){
	TreeModel treeModel = getModel();

	TreeModel.MissingValueStrategy missingValueStrategy = treeModel.getMissingValueStrategy();
	switch(missingValueStrategy){
		case NULL_PREDICTION:
			return trail.selectNull();
		case LAST_PREDICTION:
			return trail.selectLastPrediction();
		case DEFAULT_CHILD:
			return handleDefaultChild(trail, parent, context);
		case NONE:
			return null;
		default:
			throw new UnsupportedAttributeException(treeModel, missingValueStrategy);
	}
}
 
Example #10
Source File: RangerConverter.java    From jpmml-r with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<TreeModel> encodeForest(RGenericVector forest, MiningFunction miningFunction, ScoreEncoder scoreEncoder, Schema schema){
	RNumberVector<?> numTrees = forest.getNumericElement("num.trees");
	RGenericVector childNodeIDs = forest.getGenericElement("child.nodeIDs");
	RGenericVector splitVarIDs = forest.getGenericElement("split.varIDs");
	RGenericVector splitValues = forest.getGenericElement("split.values");
	RGenericVector terminalClassCounts = forest.getGenericElement("terminal.class.counts", false);

	Schema segmentSchema = schema.toAnonymousSchema();

	List<TreeModel> treeModels = new ArrayList<>();

	for(int i = 0; i < ValueUtil.asInt(numTrees.asScalar()); i++){
		TreeModel treeModel = encodeTreeModel(miningFunction, scoreEncoder, (RGenericVector)childNodeIDs.getValue(i), (RNumberVector<?>)splitVarIDs.getValue(i), (RNumberVector<?>)splitValues.getValue(i), (terminalClassCounts != null ? (RGenericVector)terminalClassCounts.getValue(i) : null), segmentSchema);

		treeModels.add(treeModel);
	}

	return treeModels;
}
 
Example #11
Source File: TreeModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
private Trail handleNoTrueChild(Trail trail){
	TreeModel treeModel = getModel();

	TreeModel.NoTrueChildStrategy noTrueChildStrategy = treeModel.getNoTrueChildStrategy();
	switch(noTrueChildStrategy){
		case RETURN_NULL_PREDICTION:
			return trail.selectNull();
		case RETURN_LAST_PREDICTION:
			Node lastPrediction = trail.getLastPrediction();

			// "Return the parent Node only if it specifies a score attribute"
			if(lastPrediction.hasScore()){
				return trail.selectLastPrediction();
			}
			return trail.selectNull();
		default:
			throw new UnsupportedAttributeException(treeModel, noTrueChildStrategy);
	}
}
 
Example #12
Source File: RangerConverter.java    From jpmml-r with GNU Affero General Public License v3.0 6 votes vote down vote up
private MiningModel encodeRegression(RGenericVector ranger, Schema schema){
	RGenericVector forest = ranger.getGenericElement("forest");

	ScoreEncoder scoreEncoder = new ScoreEncoder(){

		@Override
		public Node encode(Node node, Number splitValue, RNumberVector<?> terminalClassCount){
			node.setScore(splitValue);

			return node;
		}
	};

	List<TreeModel> treeModels = encodeForest(forest, MiningFunction.REGRESSION, scoreEncoder, schema);

	MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()))
		.setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.AVERAGE, treeModels));

	return miningModel;
}
 
Example #13
Source File: AdaConverter.java    From jpmml-r with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public RPartConverter createConverter(RGenericVector rpart){
	return new RPartConverter(rpart){

		@Override
		public boolean hasScoreDistribution(){
			return false;
		}

		@Override
		public TreeModel encodeModel(Schema schema){
			TreeModel treeModel = super.encodeModel(schema)
				.setMiningFunction(MiningFunction.REGRESSION);

			return treeModel;
		}
	};
}
 
Example #14
Source File: PMMLConverter.java    From pyramid with Apache License 2.0 6 votes vote down vote up
static
protected MiningModel createMiningModel(List<RegressionTree> regTrees, float base_score, Schema schema){
    ContinuousLabel continuousLabel = (ContinuousLabel)schema.getLabel();

    Schema segmentSchema = schema.toAnonymousSchema();

    List<TreeModel> treeModels = new ArrayList<>();

    for(RegressionTree regTree : regTrees){
        TreeModel treeModel = regTree.encodeTreeModel(segmentSchema);

        treeModels.add(treeModel);
    }

    MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(continuousLabel))
            .setMathContext(MathContext.FLOAT)
            .setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.SUM, treeModels))
            .setTargets(ModelUtil.createRescaleTargets(null, ValueUtil.floatToDouble(base_score), continuousLabel));

    return miningModel;
}
 
Example #15
Source File: TreePredictorUtil.java    From jpmml-sklearn with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public TreeModel encodeTreeModel(TreePredictor treePredictor, PredicateManager predicateManager, Schema schema){
	int[] leaf = treePredictor.isLeaf();
	int[] leftChildren = treePredictor.getLeft();
	int[] rightChildren = treePredictor.getRight();
	int[] featureIdx = treePredictor.getFeatureIdx();
	double[] thresholds = treePredictor.getThreshold();
	int[] missingGoToLeft = treePredictor.getMissingGoToLeft();
	double[] values = treePredictor.getValues();

	Node root = encodeNode(True.INSTANCE, predicateManager, 0, leaf, leftChildren, rightChildren, featureIdx, thresholds, missingGoToLeft, values, schema);

	TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
		.setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD);

	return treeModel;
}
 
Example #16
Source File: TargetUtilTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
static
private TreeModelEvaluator createTreeModelEvaluator(MiningFunction miningFunction, MathContext mathContext, Target target){
	Node root = new LeafNode(null, False.INSTANCE);

	Targets targets = new Targets()
		.addTargets(target);

	TreeModel treeModel = new TreeModel(miningFunction, new MiningSchema(), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
		.setMathContext(mathContext)
		.setTargets(targets);

	PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), new DataDictionary())
		.addModels(treeModel);

	ModelEvaluatorBuilder modelEvaluatorBuilder = new ModelEvaluatorBuilder(pmml);

	return (TreeModelEvaluator)modelEvaluatorBuilder.build();
}
 
Example #17
Source File: PMMLConverter.java    From pyramid with Apache License 2.0 6 votes vote down vote up
static
protected MiningModel createMiningModel(List<RegressionTree> regTrees, float base_score, Schema schema){
    ContinuousLabel continuousLabel = (ContinuousLabel)schema.getLabel();

    Schema segmentSchema = schema.toAnonymousSchema();

    List<TreeModel> treeModels = new ArrayList<>();

    for(RegressionTree regTree : regTrees){
        TreeModel treeModel = regTree.encodeTreeModel(segmentSchema);

        treeModels.add(treeModel);
    }

    MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(continuousLabel))
            .setMathContext(MathContext.FLOAT)
            .setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.SUM, treeModels))
            .setTargets(ModelUtil.createRescaleTargets(null, ValueUtil.floatToDouble(base_score), continuousLabel));

    return miningModel;
}
 
Example #18
Source File: TreeUtil.java    From jpmml-sklearn with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public <E extends Estimator & HasTree> TreeModel encodeTreeModel(E estimator, PredicateManager predicateManager, ScoreDistributionManager scoreDistributionManager, MiningFunction miningFunction, Schema schema){
	Tree tree = estimator.getTree();

	int[] leftChildren = tree.getChildrenLeft();
	int[] rightChildren = tree.getChildrenRight();
	int[] features = tree.getFeature();
	double[] thresholds = tree.getThreshold();
	double[] values = tree.getValues();

	Node root = encodeNode(True.INSTANCE, predicateManager, scoreDistributionManager, 0, leftChildren, rightChildren, features, thresholds, values, miningFunction, schema);

	TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);

	ClassDictUtil.clearContent(tree);

	return treeModel;
}
 
Example #19
Source File: GBMConverter.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
private MiningModel encodeBinaryClassification(List<TreeModel> treeModels, Double initF, double coefficient, Schema schema){
	Schema segmentSchema = schema.toAnonymousRegressorSchema(DataType.DOUBLE);

	MiningModel miningModel = createMiningModel(treeModels, initF, segmentSchema)
		.setOutput(ModelUtil.createPredictedOutput(FieldName.create("gbmValue"), OpType.CONTINUOUS, DataType.DOUBLE));

	return MiningModelUtil.createBinaryLogisticClassification(miningModel, -coefficient, 0d, RegressionModel.NormalizationMethod.LOGIT, true, schema);
}
 
Example #20
Source File: BinaryTreeConverter.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
private TreeModel encodeTreeModel(RGenericVector tree, Schema schema){
	Node root = encodeNode(True.INSTANCE, tree, schema);

	TreeModel treeModel = new TreeModel(this.miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);

	return treeModel;
}
 
Example #21
Source File: ModelManagerFactoryTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
public RegressorManager(PMML pmml, TreeModel treeModel){
	super(pmml, treeModel);

	MiningFunction miningFunction = treeModel.getMiningFunction();
	switch(miningFunction){
		case REGRESSION:
			break;
		default:
			throw new UnsupportedAttributeException(treeModel, miningFunction);
	}
}
 
Example #22
Source File: TreeModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public BiMap<String, Node> load(TreeModel treeModel){
	ImmutableBiMap.Builder<String, Node> builder = new ImmutableBiMap.Builder<>();

	builder = collectNodes(treeModel.getNode(), new AtomicInteger(1), builder);

	return builder.build();
}
 
Example #23
Source File: GBMConverter.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
static
private MiningModel createMiningModel(List<TreeModel> treeModels, Double initF, Schema schema){
	ContinuousLabel continuousLabel = (ContinuousLabel)schema.getLabel();

	MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(continuousLabel))
		.setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.SUM, treeModels))
		.setTargets(ModelUtil.createRescaleTargets(null, initF, continuousLabel));

	return miningModel;
}
 
Example #24
Source File: IForestConverter.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
private TreeModel encodeTreeModel(RGenericVector trees, int index, Schema schema){
	RIntegerVector nrnodes = trees.getIntegerElement("nrnodes");
	RIntegerVector ntree = trees.getIntegerElement("ntree");
	RIntegerVector nodeStatus = trees.getIntegerElement("nodeStatus");
	RIntegerVector leftDaughter = trees.getIntegerElement("lDaughter");
	RIntegerVector rightDaughter = trees.getIntegerElement("rDaughter");
	RIntegerVector splitAtt = trees.getIntegerElement("splitAtt");
	RDoubleVector splitPoint = trees.getDoubleElement("splitPoint");
	RIntegerVector nSam = trees.getIntegerElement("nSam");

	int rows = nrnodes.asScalar();
	int columns = ntree.asScalar();

	Node root = encodeNode(
		True.INSTANCE,
		0,
		0,
		FortranMatrixUtil.getColumn(nodeStatus.getValues(), rows, columns, index),
		FortranMatrixUtil.getColumn(nSam.getValues(), rows, columns, index),
		FortranMatrixUtil.getColumn(leftDaughter.getValues(), rows, columns, index),
		FortranMatrixUtil.getColumn(rightDaughter.getValues(), rows, columns, index),
		FortranMatrixUtil.getColumn(splitAtt.getValues(), rows, columns, index),
		FortranMatrixUtil.getColumn(splitPoint.getValues(), rows, columns, index),
		schema
	);

	TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);

	return treeModel;
}
 
Example #25
Source File: RangerConverter.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
private TreeModel encodeTreeModel(MiningFunction miningFunction, ScoreEncoder scoreEncoder, RGenericVector childNodeIDs, RNumberVector<?> splitVarIDs, RNumberVector<?> splitValues, RGenericVector terminalClassCounts, Schema schema){
	RNumberVector<?> leftChildIDs = (RNumberVector<?>)childNodeIDs.getValue(0);
	RNumberVector<?> rightChildIDs = (RNumberVector<?>)childNodeIDs.getValue(1);

	Node root = encodeNode(True.INSTANCE, 0, scoreEncoder, leftChildIDs, rightChildIDs, splitVarIDs, splitValues, terminalClassCounts, new CategoryManager(), schema);

	TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);

	return treeModel;
}
 
Example #26
Source File: GBMConverter.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
private MiningModel encodeMiningModel(RStringVector distributionName, List<TreeModel> treeModels, Double initF, Schema schema){

		switch(distributionName.asScalar()){
			case "gaussian":
				return encodeRegression(treeModels, initF, schema);
			case "adaboost":
				return encodeBinaryClassification(treeModels, initF, -2d, schema);
			case "bernoulli":
				return encodeBinaryClassification(treeModels, initF, -1d, schema);
			case "multinomial":
				return encodeMultinomialClassification(treeModels, initF, schema);
			default:
				throw new IllegalArgumentException();
		}
	}
 
Example #27
Source File: TreeModelCompactor.java    From jpmml-sklearn with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void enterTreeModel(TreeModel treeModel){
	TreeModel.MissingValueStrategy missingValueStrategy = treeModel.getMissingValueStrategy();
	TreeModel.NoTrueChildStrategy noTrueChildStrategy = treeModel.getNoTrueChildStrategy();
	TreeModel.SplitCharacteristic splitCharacteristic = treeModel.getSplitCharacteristic();

	if(!(TreeModel.MissingValueStrategy.NONE).equals(missingValueStrategy) || !(TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION).equals(noTrueChildStrategy) || !(TreeModel.SplitCharacteristic.BINARY_SPLIT).equals(splitCharacteristic)){
		throw new IllegalArgumentException();
	}

	this.miningFunction = treeModel.getMiningFunction();
}
 
Example #28
Source File: RegressionTree.java    From pyramid with Apache License 2.0 5 votes vote down vote up
public TreeModel encodeTreeModel(Schema schema){
    org.dmg.pmml.tree.Node root = new org.dmg.pmml.tree.Node()
            .setPredicate(new True());

    encodeNode(root, 0, schema);

    TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), root)
            .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
            .setMissingValueStrategy(TreeModel.MissingValueStrategy.NONE)
            .setMathContext(MathContext.FLOAT);

    return treeModel;
}
 
Example #29
Source File: TreeUtil.java    From jpmml-sklearn with GNU Affero General Public License v3.0 5 votes vote down vote up
static
public <E extends Estimator & HasEstimatorEnsemble<T>, T extends Estimator & HasTree> List<TreeModel> encodeTreeModelEnsemble(E estimator, MiningFunction miningFunction, Schema schema){
	PredicateManager predicateManager = new PredicateManager();
	ScoreDistributionManager scoreDistributionManager = new ScoreDistributionManager();

	return encodeTreeModelEnsemble(estimator, predicateManager, scoreDistributionManager, miningFunction, schema);
}
 
Example #30
Source File: GBMConverter.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
private TreeModel encodeTreeModel(MiningFunction miningFunction, RGenericVector tree, RGenericVector c_splits, Schema schema){
	Node root = encodeNode(True.INSTANCE, 0, tree, c_splits, new FlagManager(), new CategoryManager(), schema);

	TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.MULTI_SPLIT);

	return treeModel;
}