Java Code Examples for org.dmg.pmml.tree.TreeModel#MissingValueStrategy

The following examples show how to use org.dmg.pmml.tree.TreeModel#MissingValueStrategy . 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: 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 2
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 3
Source File: TreeModelCompactor.java    From jpmml-lightgbm 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.DEFAULT_CHILD).equals(missingValueStrategy) || !(TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION).equals(noTrueChildStrategy) || !(TreeModel.SplitCharacteristic.BINARY_SPLIT).equals(splitCharacteristic)){
		throw new IllegalArgumentException();
	}
}
 
Example 4
Source File: TreeModelCompactor.java    From jpmml-sparkml 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();

	this.replacedPredicates.clear();
}
 
Example 5
Source File: TreeModelCompactor.java    From jpmml-xgboost 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.DEFAULT_CHILD).equals(missingValueStrategy) || !(TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION).equals(noTrueChildStrategy) || !(TreeModel.SplitCharacteristic.BINARY_SPLIT).equals(splitCharacteristic)){
		throw new IllegalArgumentException();
	}
}
 
Example 6
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 7
Source File: NodeResolver.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction visit(TreeModel treeModel){
	TreeModel.MissingValueStrategy missingValueStrategy = treeModel.getMissingValueStrategy();

	switch(missingValueStrategy){
		case DEFAULT_CHILD:
			break;
		default:
			return VisitorAction.SKIP;
	}

	return super.visit(treeModel);
}
 
Example 8
Source File: UnsupportedMarkupInspector.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public VisitorAction visit(TreeModel treeModel){
	TreeModel.MissingValueStrategy missingValueStrategy = treeModel.getMissingValueStrategy();

	switch(missingValueStrategy){
		case AGGREGATE_NODES:
		case WEIGHTED_CONFIDENCE:
			report(new UnsupportedAttributeException(treeModel, missingValueStrategy));
			break;
		default:
			break;
	}

	return super.visit(treeModel);
}
 
Example 9
Source File: MissingValueStrategyTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
private NodeScoreDistribution<?> evaluate(TreeModel.MissingValueStrategy missingValueStrategy, Double missingValuePenalty, Map<FieldName, ?> arguments) throws Exception {
	TreeModelEvaluator evaluator = (TreeModelEvaluator)createModelEvaluator();

	TreeModel treeModel = evaluator.getModel()
		.setMissingValueStrategy(missingValueStrategy)
		.setMissingValuePenalty(missingValuePenalty);

	Map<FieldName, ?> results = evaluator.evaluate(arguments);

	return (NodeScoreDistribution<?>)results.get(evaluator.getTargetName());
}
 
Example 10
Source File: MissingValueStrategyTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
private NodeScoreDistribution<?> evaluate(TreeModel.MissingValueStrategy missingValueStrategy, Map<FieldName, ?> arguments) throws Exception {
	return evaluate(missingValueStrategy, null, arguments);
}