Java Code Examples for org.jpmml.evaluator.EvaluationContext#evaluate()
The following examples show how to use
org.jpmml.evaluator.EvaluationContext#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: GeneralRegressionModelEvaluator.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
static private FieldValue getVariable(FieldName name, EvaluationContext context){ FieldValue value = context.evaluate(name); if(FieldValueUtil.isMissing(value)){ throw new MissingValueException(name); } return value; }
Example 2
Source File: NearestNeighborModelEvaluator.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
private <V extends Number> List<InstanceResult<V>> evaluateInstanceRows(ValueFactory<V> valueFactory, EvaluationContext context){ NearestNeighborModel nearestNeighborModel = getModel(); ComparisonMeasure comparisonMeasure = nearestNeighborModel.getComparisonMeasure(); List<FieldValue> values = new ArrayList<>(); KNNInputs knnInputs = nearestNeighborModel.getKNNInputs(); for(KNNInput knnInput : knnInputs){ FieldName name = knnInput.getField(); if(name == null){ throw new MissingAttributeException(knnInput, PMMLAttributes.KNNINPUT_FIELD); } FieldValue value = context.evaluate(name); values.add(value); } Measure measure = MeasureUtil.ensureMeasure(comparisonMeasure); if(measure instanceof Similarity){ return evaluateSimilarity(valueFactory, comparisonMeasure, knnInputs.getKNNInputs(), values); } else if(measure instanceof Distance){ return evaluateDistance(valueFactory, comparisonMeasure, knnInputs.getKNNInputs(), values); } else { throw new UnsupportedElementException(measure); } }
Example 3
Source File: ClusteringModelEvaluator.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Override protected <V extends Number> Map<FieldName, ClusterAffinityDistribution<V>> evaluateClustering(ValueFactory<V> valueFactory, EvaluationContext context){ ClusteringModel clusteringModel = getModel(); ComparisonMeasure comparisonMeasure = clusteringModel.getComparisonMeasure(); List<ClusteringField> clusteringFields = getCenterClusteringFields(); List<FieldValue> values = new ArrayList<>(clusteringFields.size()); for(int i = 0, max = clusteringFields.size(); i < max; i++){ ClusteringField clusteringField = clusteringFields.get(i); FieldName name = clusteringField.getField(); if(name == null){ throw new MissingAttributeException(clusteringField, PMMLAttributes.CLUSTERINGFIELD_FIELD); } FieldValue value = context.evaluate(name); values.add(value); } ClusterAffinityDistribution<V> result; Measure measure = MeasureUtil.ensureMeasure(comparisonMeasure); if(measure instanceof Similarity){ result = evaluateSimilarity(valueFactory, comparisonMeasure, clusteringFields, values); } else if(measure instanceof Distance){ result = evaluateDistance(valueFactory, comparisonMeasure, clusteringFields, values); } else { throw new UnsupportedElementException(measure); } // "For clustering models, the identifier of the winning cluster is returned as the predictedValue" result.computeResult(DataType.STRING); return Collections.singletonMap(getTargetName(), result); }