Java Code Examples for org.jpmml.evaluator.ModelEvaluator#evaluate()
The following examples show how to use
org.jpmml.evaluator.ModelEvaluator#evaluate() .
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: DefaultChildTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 6 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); Map<FieldName, ?> arguments = createArguments("Integer", null, "Double", 76.45d); Map<FieldName, ?> results = evaluator.evaluate(arguments); NodeScoreDistribution<?> targetValue = (NodeScoreDistribution<?>)results.get(evaluator.getTargetName()); assertEquals("Result1", targetValue.getResult()); assertEquals("10", targetValue.getEntityId()); assertEquals(21d / 42d, targetValue.getProbability("Result1"), 1e-8); assertEquals(15d / 42d, targetValue.getProbability("Result2"), 1e-8); assertEquals(6d / 42d, targetValue.getProbability("Result3"), 1e-8); }
Example 2
Source File: AssociationOutputTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 6 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); Map<FieldName, ?> arguments = createArguments("item", Arrays.asList("Cracker", "Coke")); Map<FieldName, ?> results = evaluator.evaluate(arguments); assertEquals("1", getOutput(results, "entityId")); checkValue(Arrays.asList("Cracker"), results, "antecedent"); checkValue(Arrays.asList("Water"), results, "consequent"); checkValue("{Cracker}->{Water}", results, "rule"); checkValue("1", results, "ruleId"); checkValue(1d, results, "support"); checkValue(1d, results, "confidence"); checkValue(1d, results, "lift"); }
Example 3
Source File: ClusteringNeighborhoodTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); Map<FieldName, ?> arguments = createArguments("marital status", "d", "dependents", 0); Map<FieldName, ?> results = evaluator.evaluate(arguments); AffinityDistribution<?> targetValue = (AffinityDistribution<?>)results.get(evaluator.getTargetName()); try { targetValue.getResult(); fail(); } catch(EvaluationException ee){ // Ignored } assertNull(targetValue.getPredictionReport()); Collection<String> categories = targetValue.getCategories(); assertEquals(5, categories.size()); for(String category : categories){ assertNotNull(targetValue.getAffinity(category)); assertNull(targetValue.getAffinityReport(category)); } assertEquals(Arrays.asList("3", "1", "4"), (targetValue.getEntityIdRanking()).subList(0, 3)); assertEquals("3", getOutput(results, "neighbor1")); assertEquals("1", getOutput(results, "neighbor2")); assertEquals("4", getOutput(results, "neighbor3")); }
Example 4
Source File: ContrastMatrixTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); Map<FieldName, ?> arguments = createArguments("gender", "f", "educ", 19d, "jobcat", "3", "salbegin", 45000d); Map<FieldName, ?> results = evaluator.evaluate(arguments); FieldName lowField = FieldName.create("Probability_Low"); FieldName highField = FieldName.create("Probability_High"); // Expected values have been calculated by hand assertEquals(0.81956470d, (Double)getOutput(results, lowField), 1e-8); assertEquals(0.18043530d, (Double)getOutput(results, highField), 1e-8); }
Example 5
Source File: MissingPredictionTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
static private Integer evaluate(ModelEvaluator<?> evaluator, Double x){ Map<FieldName, ?> arguments = createArguments("x", x); Map<FieldName, ?> results = evaluator.evaluate(arguments); return (Integer)getTarget(results, "y"); }
Example 6
Source File: ModelNestingTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); List<InputField> inputFields = evaluator.getInputFields(); List<TargetField> targetFields = evaluator.getTargetFields(); List<OutputField> outputFields = evaluator.getOutputFields(); assertEquals(1, inputFields.size()); assertEquals(0, targetFields.size()); assertEquals(2, outputFields.size()); try { evaluator.getTargetField(); fail(); } catch(EvaluationException ee){ // Ignored } assertEquals(Evaluator.DEFAULT_TARGET_NAME, evaluator.getTargetName()); Map<FieldName, ?> arguments = createArguments("input", 2d); Map<FieldName, ?> results = evaluator.evaluate(arguments); assertEquals(3, results.size()); assertEquals(2d * 2d, (Double)getTarget(results, Evaluator.DEFAULT_TARGET_NAME), 1e-8d); assertNotNull((Double)getOutput(results, "output")); assertNull(getOutput(results, "report(output)")); }
Example 7
Source File: ScalarVerificationTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Test public void verify() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); evaluator.verify(); Map<FieldName, ?> arguments = createArguments("sepal length", 5.1, "sepal width", 3.5, "petal length", 1.4, "petal width", 0.2); Map<FieldName, ?> results = evaluator.evaluate(arguments); assertEquals(1 + 4, results.size()); assertEquals("setosa", getTarget(results, "species")); assertEquals("setosa", getOutput(results, "predicted species")); assertEquals(1.0, getOutput(results, "probability setosa")); assertEquals(0.0, getOutput(results, "probability versicolor")); assertEquals(0.0, getOutput(results, "probability virginica")); }
Example 8
Source File: EmptyTargetCategoryTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); Map<FieldName, ?> arguments = createArguments("x1", 3d, "x2", 3d); Map<FieldName, ?> results = evaluator.evaluate(arguments); ProbabilityDistribution<?> targetValue = (ProbabilityDistribution<?>)results.get(evaluator.getTargetName()); assertEquals("yes", targetValue.getResult()); double value = (3d * -28.6617384d + 3d * -20.42027426d + 125.56601826d); assertEquals(Math.exp(0d) / (Math.exp(0d) + Math.exp(value)), targetValue.getProbability("yes"), 1e-8); assertEquals(Math.exp(value) / (Math.exp(0d) + Math.exp(value)), targetValue.getProbability("no"), 1e-8); assertNull(targetValue.getPredictionReport()); }
Example 9
Source File: CategoricalResidualTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); Map<FieldName, ?> arguments = createArguments("input", (2d * 0.8d), "target", "yes"); Map<FieldName, ?> results = evaluator.evaluate(arguments); FieldName name = FieldName.create("residual"); assertEquals(0.2d, (Double)getOutput(results, name), 1e-8); arguments = createArguments("input", (2d * 0.8d), "target", "no"); results = evaluator.evaluate(arguments); assertEquals(-0.8d, (Double)getOutput(results, name), 1e-8); }
Example 10
Source File: MultiTargetTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Test public void evaluateWithProbability() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); evaluator.addResultFeatures(EnumSet.of(ResultFeature.PROBABILITY)); Map<FieldName, ?> arguments = createArguments("x", -1.0d); Map<FieldName, ?> results = evaluator.evaluate(arguments); Classification<?, ?> classification = (Classification<?, ?>)results.get(FieldName.create("y1")); assertTrue(classification instanceof NodeScoreDistribution); arguments = createArguments("x", 1.0d); results = evaluator.evaluate(arguments); classification = (Classification<?, ?>)results.get(FieldName.create("y2")); assertTrue(classification instanceof ProbabilityDistribution); }
Example 11
Source File: RankingTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); checkTargetFields(Collections.singletonList(null), evaluator); Map<FieldName, ?> arguments = createArguments("input", 1d); Map<FieldName, ?> results = evaluator.evaluate(arguments); ClusterAffinityDistribution<?> affinityDistribution = (ClusterAffinityDistribution<?>)results.get(evaluator.getTargetName()); assertEquals("2", affinityDistribution.getResult()); checkValue("2", 1d, results, "first"); checkValue("3", 4d, results, "second"); checkValue("1", 16d, results, "third"); }
Example 12
Source File: MultiTargetTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 3 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); assertTrue(evaluator.hasResultFeature(ResultFeature.PREDICTED_VALUE)); checkResultFields(Arrays.asList("y1", "y2"), Arrays.asList("decision"), evaluator); Map<FieldName, ?> arguments = createArguments("x", -1.0d); Map<FieldName, ?> results = evaluator.evaluate(arguments); assertNotNull(getTarget(results, "y1")); assertNull(getTarget(results, "y2")); Classification<?, ?> classification = (Classification<?, ?>)results.get(FieldName.create("y1")); assertTrue(classification instanceof NodeScoreDistribution); assertEquals(0, getOutput(results, "decision")); arguments = createArguments("x", 1.0d); results = evaluator.evaluate(arguments); assertNull(getTarget(results, "y1")); assertNotNull(getTarget(results, "y2")); classification = (Classification<?, ?>)results.get(FieldName.create("y2")); assertFalse(classification instanceof ProbabilityDistribution); assertEquals(1, getOutput(results, "decision")); }
Example 13
Source File: AlternateBinaryTargetCategoryTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 3 votes |
private String evaluate(double x1, double x2) throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); Map<FieldName, ?> arguments = createArguments("x1", x1, "x2", x2); Map<FieldName, ?> results = evaluator.evaluate(arguments); Classification<?, ?> targetValue = (Classification<?, ?>)results.get(evaluator.getTargetName()); return (String)targetValue.getResult(); }
Example 14
Source File: VectorInstanceTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 3 votes |
private double evaluate(double x1, double x2) throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); Map<FieldName, ?> arguments = createArguments("x1", x1, "x2", x2); Map<FieldName, ?> results = evaluator.evaluate(arguments); return (Double)results.get(evaluator.getTargetName()); }
Example 15
Source File: ContinuousResidualTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 3 votes |
@Test public void evaluate() throws Exception { ModelEvaluator<?> evaluator = createModelEvaluator(); List<InputField> activeFields = evaluator.getActiveFields(); assertEquals(1, activeFields.size()); List<InputField> inputFields = new ArrayList<>(evaluator.getInputFields()); assertEquals(2, inputFields.size()); inputFields.removeAll(activeFields); assertEquals(1, inputFields.size()); InputField inputField = Iterables.getOnlyElement(inputFields); assertTrue(inputField instanceof ResidualInputField); Map<FieldName, ?> arguments = createArguments("input", 0.8d, "target", 3d); Map<FieldName, ?> results = evaluator.evaluate(arguments); FieldName name = FieldName.create("residual"); assertEquals(2.6d, (Double)getOutput(results, name), 1e-8); arguments = createArguments("input", 0.8d, "target", null); results = evaluator.evaluate(arguments); assertEquals(1.6d, (Double)getOutput(results, name), 1e-8); }
Example 16
Source File: ClassificationOutputTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 3 votes |
@Test public void evaluate() throws Exception { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); Configuration configuration = configurationBuilder.build(); ModelEvaluator<?> evaluator = createModelEvaluator(configuration); checkResultFields(Arrays.asList("result"), Arrays.asList("output_predictedValue", "output_predictedDisplayValue", "output_probability"), evaluator); Map<FieldName, ?> arguments = createArguments("flag", false); Map<FieldName, ?> results = evaluator.evaluate(arguments); assertEquals(1 + 3, results.size()); assertEquals("0", getTarget(results, "result")); assertEquals("0", getOutput(results, "output_predictedValue")); assertEquals("zero", getOutput(results, "output_predictedDisplayValue")); assertEquals(1d, getOutput(results, "output_probability")); configurationBuilder.setOutputFilter(OutputFilters.KEEP_FINAL_RESULTS); configuration = configurationBuilder.build(); evaluator.configure(configuration); checkResultFields(Arrays.asList("result"), Arrays.asList("output_predictedDisplayValue", "output_probability"), evaluator); results = evaluator.evaluate(arguments); assertEquals(1 + 2, results.size()); }
Example 17
Source File: RegressionOutputTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 3 votes |
@Test public void evaluate() throws Exception { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); Configuration configuration = configurationBuilder.build(); ModelEvaluator<?> evaluator = createModelEvaluator(configuration); checkResultFields(Arrays.asList("result"), Arrays.asList("RawResult", "RawIntegerResult", "FinalResult", "FinalIntegerResult", "BusinessDecision"), evaluator); Map<FieldName, ?> arguments = createArguments("input", 4d); Map<FieldName, ?> results = evaluator.evaluate(arguments); assertEquals(1 + 5, results.size()); assertEquals(8d, getTarget(results, "result")); assertEquals(8d, getOutput(results, "RawResult")); assertEquals(8, getOutput(results, "RawIntegerResult")); assertEquals(35d, getOutput(results, "FinalResult")); assertEquals(35, getOutput(results, "FinalIntegerResult")); assertEquals("waive", getOutput(results, "BusinessDecision")); configurationBuilder.setOutputFilter(OutputFilters.KEEP_FINAL_RESULTS); configuration = configurationBuilder.build(); evaluator.configure(configuration); checkResultFields(Arrays.asList("result"), Arrays.asList("FinalResult", "FinalIntegerResult", "BusinessDecision"), evaluator); results = evaluator.evaluate(arguments); assertEquals(1 + 3, results.size()); }
Example 18
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 19
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)); }