org.dmg.pmml.TargetValue Java Examples
The following examples show how to use
org.dmg.pmml.TargetValue.
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: TargetUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 6 votes |
static public TargetValue getTargetValue(Target target, Object value){ DataType dataType = TypeUtil.getDataType(value); List<TargetValue> targetValues = target.getTargetValues(); for(TargetValue targetValue : targetValues){ Object simpleValue = targetValue.getValue(); if(simpleValue == null){ throw new MissingAttributeException(targetValue, PMMLAttributes.TARGETVALUE_VALUE); } // End if if((value).equals(TypeUtil.parseOrCast(dataType, simpleValue))){ return targetValue; } } return null; }
Example #2
Source File: VersionInspectorTest.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 5 votes |
static private TargetValue createTargetValue(String value){ TargetValue targetValue = new TargetValue() .setValue(value); return targetValue; }
Example #3
Source File: TargetUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
static private <V extends Number> Value<V> getDefaultValue(ValueFactory<V> valueFactory, Target target){ if(!target.hasTargetValues()){ return null; } List<TargetValue> targetValues = target.getTargetValues(); if(targetValues.size() != 1){ throw new InvalidElementListException(targetValues); } TargetValue targetValue = targetValues.get(0); Number defaultValue = targetValue.getDefaultValue(); // "The value and priorProbability attributes are used only if the optype of the field is categorical or ordinal" if(targetValue.getValue() != null || targetValue.getPriorProbability() != null){ throw new InvalidElementException(targetValue); } // End if if(defaultValue == null){ return null; } return valueFactory.newValue(defaultValue); }
Example #4
Source File: TargetCategoryParser.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Override public VisitorAction visit(TargetValue targetValue){ Target target = (Target)getParent(); targetValue.setValue(parseTargetValue(target.getField(), targetValue.getValue())); return super.visit(targetValue); }
Example #5
Source File: TargetUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 3 votes |
@Test public void evaluateRegressionDefault(){ TargetValue targetValue = new TargetValue() .setDefaultValue(Math.PI); Target target = new Target() .setField(null) .addTargetValues(targetValue); ModelEvaluator<?> evaluator = createTreeModelEvaluator(MiningFunction.REGRESSION, MathContext.FLOAT, target); DataField dataField = evaluator.getDataField(target.getField()); assertEquals(OpType.CONTINUOUS, dataField.getOpType()); assertEquals(DataType.FLOAT, dataField.getDataType()); Map<FieldName, ?> results = evaluator.evaluate(Collections.emptyMap()); assertEquals((float)Math.PI, results.get(dataField.getName())); evaluator = createTreeModelEvaluator(MiningFunction.REGRESSION, MathContext.DOUBLE, target); dataField = evaluator.getDefaultDataField(); assertEquals(OpType.CONTINUOUS, dataField.getOpType()); assertEquals(DataType.DOUBLE, dataField.getDataType()); results = evaluator.evaluate(Collections.emptyMap()); assertEquals(Math.PI, results.get(dataField.getName())); }
Example #6
Source File: DefaultValueTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 3 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); Model model = evaluator.getModel(); Map<FieldName, ?> arguments = createArguments("input", null); Map<FieldName, ?> results = evaluator.evaluate(arguments); assertEquals(1, results.size()); assertEquals(432.21d, getTarget(results, Evaluator.DEFAULT_TARGET_NAME)); Targets targets = model.getTargets(); for(Target target : targets){ List<TargetValue> targetValues = target.getTargetValues(); targetValues.clear(); } results = evaluator.evaluate(arguments); assertEquals(1, results.size()); assertEquals(null, getTarget(results, Evaluator.DEFAULT_TARGET_NAME)); }
Example #7
Source File: PriorProbabilitiesTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 3 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); Model model = evaluator.getModel(); Map<FieldName, ?> arguments = createArguments("input", null); Map<FieldName, ?> results = evaluator.evaluate(arguments); assertEquals(5, results.size()); assertEquals("NO", getTarget(results, Evaluator.DEFAULT_TARGET_NAME)); assertEquals("NO", getOutput(results, "I_response")); assertEquals("No", getOutput(results, "U_response")); assertEquals(0.02d, getOutput(results, "P_responseYes")); assertEquals(0.98d, getOutput(results, "P_responseNo")); Targets targets = model.getTargets(); for(Target target : targets){ List<TargetValue> targetValues = target.getTargetValues(); targetValues.clear(); } results = evaluator.evaluate(arguments); assertEquals(1, results.size()); assertEquals(null, getTarget(results, Evaluator.DEFAULT_TARGET_NAME)); }
Example #8
Source File: TargetUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 2 votes |
@Test public void evaluateClassificationDefault(){ TargetValue yesValue = new TargetValue() .setValue("yes") .setPriorProbability(1d / 7d); TargetValue noValue = new TargetValue() .setValue("no") .setPriorProbability(1d - NumberUtil.asDouble(yesValue.getPriorProbability())); Target target = new Target() .setField(null) .addTargetValues(yesValue, noValue); ModelEvaluator<?> evaluator = createTreeModelEvaluator(MiningFunction.CLASSIFICATION, MathContext.FLOAT, target); DataField dataField = evaluator.getDataField(target.getField()); assertEquals(OpType.CATEGORICAL, dataField.getOpType()); assertEquals(DataType.STRING, dataField.getDataType()); Map<FieldName, ?> results = evaluator.evaluate(Collections.emptyMap()); HasProbability hasProbability = (HasProbability)results.get(dataField.getName()); assertEquals((Double)((double)(float)(1d / 7d)), hasProbability.getProbability("yes")); assertEquals((Double)((double)(float)(1d - (1d / 7d))), hasProbability.getProbability("no")); evaluator = createTreeModelEvaluator(MiningFunction.CLASSIFICATION, MathContext.DOUBLE, target); dataField = evaluator.getDataField(target.getField()); assertEquals(OpType.CATEGORICAL, dataField.getOpType()); assertEquals(DataType.STRING, dataField.getDataType()); results = evaluator.evaluate(Collections.emptyMap()); hasProbability = (HasProbability)results.get(dataField.getName()); assertEquals(yesValue.getPriorProbability(), hasProbability.getProbability("yes")); assertEquals(noValue.getPriorProbability(), hasProbability.getProbability("no")); }