org.jpmml.converter.PredicateManager Java Examples
The following examples show how to use
org.jpmml.converter.PredicateManager.
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: TreeUtil.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 6 votes |
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 #2
Source File: TreeModelUtil.java From jpmml-sparkml with GNU Affero General Public License v3.0 | 6 votes |
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 #3
Source File: TreePredictorUtil.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 6 votes |
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 #4
Source File: TreeModelUtil.java From jpmml-sparkml with GNU Affero General Public License v3.0 | 5 votes |
static private <M extends Model<M> & DecisionTreeModel> TreeModel encodeTreeModel(M model, PredicateManager predicateManager, MiningFunction miningFunction, ScoreEncoder scoreEncoder, Schema schema){ Node root = encodeNode(True.INSTANCE, model.rootNode(), predicateManager, new CategoryManager(), scoreEncoder, schema); TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT); return treeModel; }
Example #5
Source File: RegTree.java From jpmml-xgboost with GNU Affero General Public License v3.0 | 5 votes |
public TreeModel encodeTreeModel(PredicateManager predicateManager, Schema schema){ org.dmg.pmml.tree.Node root = encodeNode(True.INSTANCE, predicateManager, 0, schema); TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), root) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT) .setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD) .setMathContext(MathContext.FLOAT); return treeModel; }
Example #6
Source File: TreeUtil.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 5 votes |
static public <E extends Estimator & HasTree> TreeModel encodeTreeModel(E estimator, MiningFunction miningFunction, Schema schema){ PredicateManager predicateManager = new PredicateManager(); ScoreDistributionManager scoreDistributionManager = new ScoreDistributionManager(); return encodeTreeModel(estimator, predicateManager, scoreDistributionManager, miningFunction, schema); }
Example #7
Source File: Tree.java From jpmml-lightgbm with GNU Affero General Public License v3.0 | 5 votes |
public TreeModel encodeTreeModel(PredicateManager predicateManager, Schema schema){ Node root = encodeNode(True.INSTANCE, predicateManager, new CategoryManager(), 0, 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 #8
Source File: TreeUtil.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 5 votes |
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 #9
Source File: TreePredictorUtil.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 4 votes |
static public TreeModel encodeTreeModel(TreePredictor treePredictor, Schema schema){ PredicateManager predicateManager = new PredicateManager(); return encodeTreeModel(treePredictor, predicateManager, schema); }
Example #10
Source File: TreeModelConverter.java From jpmml-r with GNU Affero General Public License v3.0 | 4 votes |
public PredicateManager getPredicateManager(){ return this.predicateManager; }
Example #11
Source File: TreeModelConverter.java From jpmml-r with GNU Affero General Public License v3.0 | 4 votes |
public Predicate createSimplePredicate(Feature feature, SimplePredicate.Operator operator, Object value){ PredicateManager predicateManager = getPredicateManager(); return predicateManager.createSimplePredicate(feature, operator, value); }
Example #12
Source File: TreeModelConverter.java From jpmml-r with GNU Affero General Public License v3.0 | 4 votes |
public Predicate createSimpleSetPredicate(Feature feature, List<?> values){ PredicateManager predicateManager = getPredicateManager(); return predicateManager.createSimpleSetPredicate(feature, values); }
Example #13
Source File: HistGradientBoostingUtil.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 4 votes |
static public MiningModel encodeHistGradientBoosting(List<TreePredictor> treePredictors, Number baselinePrediction, Schema schema){ ContinuousLabel continuousLabel = (ContinuousLabel)schema.getLabel(); PredicateManager predicateManager = new PredicateManager(); Schema segmentSchema = schema.toAnonymousRegressorSchema(DataType.DOUBLE); List<TreeModel> treeModels = new ArrayList<>(); for(TreePredictor treePredictor : treePredictors){ TreeModel treeModel = TreePredictorUtil.encodeTreeModel(treePredictor, predicateManager, segmentSchema); treeModels.add(treeModel); } MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(continuousLabel)) .setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.SUM, treeModels)) .setTargets(ModelUtil.createRescaleTargets(null, baselinePrediction, continuousLabel)); return miningModel; }
Example #14
Source File: ObjFunction.java From jpmml-xgboost with GNU Affero General Public License v3.0 | 4 votes |
static protected MiningModel createMiningModel(List<RegTree> trees, List<Float> weights, float base_score, Integer ntreeLimit, Schema schema){ if(weights != null){ if(trees.size() != weights.size()){ throw new IllegalArgumentException(); } } // End if if(ntreeLimit != null){ if(ntreeLimit > trees.size()){ throw new IllegalArgumentException("Tree limit " + ntreeLimit + " is greater than the number of trees"); } trees = trees.subList(0, ntreeLimit); if(weights != null){ weights = weights.subList(0, ntreeLimit); } } // End if if(weights != null){ weights = new ArrayList<>(weights); } ContinuousLabel continuousLabel = (ContinuousLabel)schema.getLabel(); Schema segmentSchema = schema.toAnonymousSchema(); PredicateManager predicateManager = new PredicateManager(); List<TreeModel> treeModels = new ArrayList<>(); boolean equalWeights = true; Iterator<RegTree> treeIt = trees.iterator(); Iterator<Float> weightIt = (weights != null ? weights.iterator() : null); while(treeIt.hasNext()){ RegTree tree = treeIt.next(); Float weight = (weightIt != null ? weightIt.next() : null); if(tree.isEmpty()){ weightIt.remove(); continue; } // End if if(weight != null){ equalWeights &= ValueUtil.isOne(weight); } TreeModel treeModel = tree.encodeTreeModel(predicateManager, segmentSchema); treeModels.add(treeModel); } MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(continuousLabel)) .setMathContext(MathContext.FLOAT) .setSegmentation(MiningModelUtil.createSegmentation(equalWeights ? Segmentation.MultipleModelMethod.SUM : Segmentation.MultipleModelMethod.WEIGHTED_SUM, treeModels, weights)) .setTargets(ModelUtil.createRescaleTargets(null, base_score, continuousLabel)); return miningModel; }
Example #15
Source File: TreeModelUtil.java From jpmml-sparkml with GNU Affero General Public License v3.0 | 4 votes |
static public <C extends ModelConverter<? extends M> & HasTreeOptions, M extends Model<M> & TreeEnsembleModel<T>, T extends Model<T> & DecisionTreeModel> List<TreeModel> encodeDecisionTreeEnsemble(C converter, Schema schema){ PredicateManager predicateManager = new PredicateManager(); return encodeDecisionTreeEnsemble(converter, predicateManager, schema); }
Example #16
Source File: TreeModelUtil.java From jpmml-sparkml with GNU Affero General Public License v3.0 | 4 votes |
static public <C extends ModelConverter<? extends M> & HasTreeOptions, M extends Model<M> & DecisionTreeModel> TreeModel encodeDecisionTree(C converter, PredicateManager predicateManager, Schema schema){ return encodeDecisionTree(converter, converter.getTransformer(), predicateManager, schema); }
Example #17
Source File: TreeModelUtil.java From jpmml-sparkml with GNU Affero General Public License v3.0 | 4 votes |
static public <C extends ModelConverter<? extends M> & HasTreeOptions, M extends Model<M> & DecisionTreeModel> TreeModel encodeDecisionTree(C converter, Schema schema){ PredicateManager predicateManager = new PredicateManager(); return encodeDecisionTree(converter, predicateManager, schema); }
Example #18
Source File: ObjectiveFunction.java From jpmml-lightgbm with GNU Affero General Public License v3.0 | 3 votes |
protected MiningModel createMiningModel(List<Tree> trees, Integer numIteration, Schema schema){ ContinuousLabel continuousLabel = (ContinuousLabel)schema.getLabel(); Schema segmentSchema = schema.toAnonymousSchema(); PredicateManager predicateManager = new PredicateManager(); List<TreeModel> treeModels = new ArrayList<>(); if(numIteration != null){ if(numIteration > trees.size()){ throw new IllegalArgumentException("Tree limit " + numIteration + " is greater than the number of trees"); } trees = trees.subList(0, numIteration); } for(Tree tree : trees){ TreeModel treeModel = tree.encodeTreeModel(predicateManager, segmentSchema); treeModels.add(treeModel); } MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(continuousLabel)) .setSegmentation(MiningModelUtil.createSegmentation(this.average_output_ ? Segmentation.MultipleModelMethod.AVERAGE : Segmentation.MultipleModelMethod.SUM, treeModels)); return miningModel; }