本文整理汇总了Java中org.dmg.pmml.tree.TreeModel类的典型用法代码示例。如果您正苦于以下问题:Java TreeModel类的具体用法?Java TreeModel怎么用?Java TreeModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TreeModel类属于org.dmg.pmml.tree包,在下文中一共展示了TreeModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
@Override
public VisitorAction visit(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();
}
treeModel
.setMissingValueStrategy(TreeModel.MissingValueStrategy.NONE)
.setNoTrueChildStrategy(TreeModel.NoTrueChildStrategy.RETURN_LAST_PREDICTION)
.setSplitCharacteristic(TreeModel.SplitCharacteristic.MULTI_SPLIT);
return super.visit(treeModel);
}
示例2: encodeModel
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
@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);
}
示例3: encodeTreeModel
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
static
public 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;
}
示例4: encodeTreeModel
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
static
public <E extends Estimator & HasTree> TreeModel encodeTreeModel(E estimator, PredicateManager predicateManager, 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 = new Node()
.setId("1")
.setPredicate(new True());
encodeNode(root, predicateManager, 0, leftChildren, rightChildren, features, thresholds, values, miningFunction, schema);
TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root)
.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);
return treeModel;
}
示例5: encodeRegression
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
private MiningModel encodeRegression(RGenericVector ranger, Schema schema){
RGenericVector forest = (RGenericVector)ranger.getValue("forest");
ScoreEncoder scoreEncoder = new ScoreEncoder(){
@Override
public void encode(Node node, Number splitValue, RNumberVector<?> terminalClassCount){
node.setScore(ValueUtil.formatValue(splitValue));
}
};
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;
}
示例6: encodeForest
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
private List<TreeModel> encodeForest(RGenericVector forest, MiningFunction miningFunction, ScoreEncoder scoreEncoder, Schema schema){
RNumberVector<?> numTrees = (RNumberVector<?>)forest.getValue("num.trees");
RGenericVector childNodeIDs = (RGenericVector)forest.getValue("child.nodeIDs");
RGenericVector splitVarIDs = (RGenericVector)forest.getValue("split.varIDs");
RGenericVector splitValues = (RGenericVector)forest.getValue("split.values");
RGenericVector terminalClassCounts = (RGenericVector)forest.getValue("terminal.class.counts", true);
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;
}
示例7: createMiningModel
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
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;
}
示例8: handleNoTrueChild
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
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);
}
}
示例9: handleMissingValue
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
/**
* @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);
}
}
示例10: defaultChildSinglePenalty
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
@Test
public void defaultChildSinglePenalty() throws Exception {
Map<FieldName, ?> arguments = createArguments("outlook", null, "temperature", 40d, "humidity", 70d);
NodeScoreDistribution<?> targetValue = evaluate(TreeModel.MissingValueStrategy.DEFAULT_CHILD, 0.8d, arguments);
assertEquals("4", targetValue.getEntityId());
assertEquals((Double)0.4d, targetValue.getProbability("will play"));
assertEquals((Double)0d, targetValue.getProbability("may play"));
assertEquals((Double)0.6d, targetValue.getProbability("no play"));
double missingValuePenatly = 0.8d;
assertEquals((Double)(0.4d * missingValuePenatly), targetValue.getConfidence("will play"));
assertEquals((Double)(0d * missingValuePenatly), targetValue.getConfidence("may play"));
assertEquals((Double)(0.6d * missingValuePenatly), targetValue.getConfidence("no play"));
}
示例11: defaultChildMultiplePenalties
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
@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"));
}
示例12: createTreeModelEvaluator
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
static
private TreeModelEvaluator createTreeModelEvaluator(MiningFunction miningFunction, MathContext mathContext, Target target){
Node root = new Node()
.setPredicate(new False());
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);
return new TreeModelEvaluator(pmml);
}
示例13: visit
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
@Override
public VisitorAction visit(Node node){
TreeModel treeModel = getTreeModel();
MiningFunction miningFunction = treeModel.getMiningFunction();
switch(miningFunction){
case REGRESSION:
if(node.hasScoreDistributions()){
List<ScoreDistribution> scoreDistributions = node.getScoreDistributions();
scoreDistributions.clear();
}
break;
default:
break;
}
return super.visit(node);
}
示例14: clean
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
@Test
public void clean(){
Node node = new Node()
.setPredicate(new True())
.setScore("1")
.addScoreDistributions(new ScoreDistribution("0", 0), new ScoreDistribution("1", 100));
TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, new MiningSchema(), node);
ScoreDistributionCleaner cleaner = new ScoreDistributionCleaner();
cleaner.applyTo(treeModel);
assertTrue(node.hasScoreDistributions());
treeModel.setMiningFunction(MiningFunction.REGRESSION);
cleaner.applyTo(treeModel);
assertFalse(node.hasScoreDistributions());
}
示例15: intern
import org.dmg.pmml.tree.TreeModel; //导入依赖的package包/类
@Test
public void intern(){
ScoreDistribution left = new ScoreDistribution("event", 0.33d);
ScoreDistribution right = new ScoreDistribution("event", 0.33d);
Node leftChild = createNode(left);
Node rightChild = createNode(right);
Node root = new Node()
.setPredicate(new True())
.addNodes(leftChild, rightChild);
TreeModel treeModel = new TreeModel()
.setNode(root);
for(int i = 0; i < 2; i++){
assertNotSame((leftChild.getScoreDistributions()).get(i), (rightChild.getScoreDistributions()).get(i));
}
intern(treeModel);
for(int i = 0; i < 2; i++){
assertSame((leftChild.getScoreDistributions()).get(i), (rightChild.getScoreDistributions()).get(i));
}
}