Java Code Examples for org.jpmml.converter.mining.MiningModelUtil#createBinaryLogisticClassification()
The following examples show how to use
org.jpmml.converter.mining.MiningModelUtil#createBinaryLogisticClassification() .
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: GBTClassificationModelConverter.java From jpmml-sparkml with GNU Affero General Public License v3.0 | 6 votes |
@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 = schema.toAnonymousRegressorSchema(DataType.DOUBLE); List<TreeModel> treeModels = TreeModelUtil.encodeDecisionTreeEnsemble(this, 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); }
Example 2
Source File: LinearSVCModelConverter.java From jpmml-sparkml with GNU Affero General Public License v3.0 | 6 votes |
@Override public MiningModel encodeModel(Schema schema){ LinearSVCModel model = getTransformer(); Transformation transformation = new AbstractTransformation(){ @Override public Expression createExpression(FieldRef fieldRef){ return PMMLUtil.createApply(PMMLFunctions.THRESHOLD) .addExpressions(fieldRef, PMMLUtil.createConstant(model.getThreshold())); } }; Schema segmentSchema = schema.toAnonymousRegressorSchema(DataType.DOUBLE); Model linearModel = LinearModelUtil.createRegression(this, model.coefficients(), model.intercept(), segmentSchema) .setOutput(ModelUtil.createPredictedOutput(FieldName.create("margin"), OpType.CONTINUOUS, DataType.DOUBLE, transformation)); return MiningModelUtil.createBinaryLogisticClassification(linearModel, 1d, 0d, RegressionModel.NormalizationMethod.NONE, false, schema); }
Example 3
Source File: HingeClassification.java From jpmml-xgboost with GNU Affero General Public License v3.0 | 6 votes |
@Override public MiningModel encodeMiningModel(List<RegTree> trees, List<Float> weights, float base_score, Integer ntreeLimit, Schema schema){ Schema segmentSchema = schema.toAnonymousRegressorSchema(DataType.FLOAT); Transformation transformation = new FunctionTransformation(PMMLFunctions.THRESHOLD){ @Override public FieldName getName(FieldName name){ return FieldName.create("hinge(" + name + ")"); } @Override public Expression createExpression(FieldRef fieldRef){ Apply apply = (Apply)super.createExpression(fieldRef); apply.addExpressions(PMMLUtil.createConstant(0f)); return apply; } }; MiningModel miningModel = createMiningModel(trees, weights, base_score, ntreeLimit, segmentSchema) .setOutput(ModelUtil.createPredictedOutput(FieldName.create("xgbValue"), OpType.CONTINUOUS, DataType.FLOAT, transformation)); return MiningModelUtil.createBinaryLogisticClassification(miningModel, 1d, 0d, RegressionModel.NormalizationMethod.NONE, true, schema); }
Example 4
Source File: GBDTLRClassifier.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 6 votes |
@Override public Model encodeModel(Schema schema){ Classifier gbdt = getGBDT(); MultiOneHotEncoder ohe = getOHE(); LinearClassifier lr = getLR(); CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel(); SchemaUtil.checkSize(2, categoricalLabel); List<? extends Number> coef = lr.getCoef(); List<? extends Number> intercept = lr.getIntercept(); Schema segmentSchema = schema.toAnonymousSchema(); MiningModel miningModel = GBDTUtil.encodeModel(gbdt, ohe, coef, Iterables.getOnlyElement(intercept), segmentSchema) .setOutput(ModelUtil.createPredictedOutput(FieldName.create("decisionFunction"), OpType.CONTINUOUS, DataType.DOUBLE)); return MiningModelUtil.createBinaryLogisticClassification(miningModel, 1d, 0d, RegressionModel.NormalizationMethod.LOGIT, lr.hasProbabilityDistribution(), schema); }
Example 5
Source File: AdaConverter.java From jpmml-r with GNU Affero General Public License v3.0 | 6 votes |
@Override public Model encodeModel(Schema schema){ RGenericVector ada = getObject(); RGenericVector model = ada.getGenericElement("model"); RGenericVector trees = model.getGenericElement("trees"); RDoubleVector alpha = model.getDoubleElement("alpha"); List<TreeModel> treeModels = encodeTreeModels(trees); MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(null)) .setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.WEIGHTED_SUM, treeModels, alpha.getValues())) .setOutput(ModelUtil.createPredictedOutput(FieldName.create("adaValue"), OpType.CONTINUOUS, DataType.DOUBLE)); return MiningModelUtil.createBinaryLogisticClassification(miningModel, 2d, 0d, RegressionModel.NormalizationMethod.LOGIT, true, schema); }
Example 6
Source File: BinomialLogisticRegression.java From jpmml-lightgbm with GNU Affero General Public License v3.0 | 5 votes |
@Override public MiningModel encodeMiningModel(List<Tree> trees, Integer numIteration, Schema schema){ Schema segmentSchema = schema.toAnonymousRegressorSchema(DataType.DOUBLE); MiningModel miningModel = createMiningModel(trees, numIteration, segmentSchema) .setOutput(ModelUtil.createPredictedOutput(FieldName.create("lgbmValue"), OpType.CONTINUOUS, DataType.DOUBLE)); return MiningModelUtil.createBinaryLogisticClassification(miningModel, BinomialLogisticRegression.this.sigmoid_, 0d, RegressionModel.NormalizationMethod.LOGIT, true, schema); }
Example 7
Source File: BinomialLogisticRegression.java From jpmml-xgboost with GNU Affero General Public License v3.0 | 5 votes |
@Override public MiningModel encodeMiningModel(List<RegTree> trees, List<Float> weights, float base_score, Integer ntreeLimit, Schema schema){ Schema segmentSchema = schema.toAnonymousRegressorSchema(DataType.FLOAT); MiningModel miningModel = createMiningModel(trees, weights, base_score, ntreeLimit, segmentSchema) .setOutput(ModelUtil.createPredictedOutput(FieldName.create("xgbValue"), OpType.CONTINUOUS, DataType.FLOAT)); return MiningModelUtil.createBinaryLogisticClassification(miningModel, 1d, 0d, RegressionModel.NormalizationMethod.LOGIT, true, schema); }
Example 8
Source File: GBMConverter.java From jpmml-r with GNU Affero General Public License v3.0 | 5 votes |
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); }