org.jpmml.evaluator.ModelEvaluator Java Examples

The following examples show how to use org.jpmml.evaluator.ModelEvaluator. 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: MLModelRegistryService.java    From streamline with Apache License 2.0 6 votes vote down vote up
private List<MLModelField> doGetOutputFieldsForPMMLStream(String pmmlContents) throws SAXException, JAXBException, UnsupportedEncodingException {
    List<MLModelField> fieldNames = new ArrayList<>();
    PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes("UTF-8"))));
    Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
    modelEvaluator.getPredictedFields().forEach((f) -> fieldNames.add(getModelField(modelEvaluator.getDataField(f))));

    modelEvaluator.getOutputFields().forEach((f) -> {
        OutputField outputField = modelEvaluator.getOutputField(f);
        ResultFeatureType resultFeatureType = outputField.getFeature();
        if (resultFeatureType != ResultFeatureType.PREDICTED_VALUE &&
                resultFeatureType != ResultFeatureType.PREDICTED_DISPLAY_VALUE) {
            fieldNames.add(getModelField(outputField));
        }
    });

    return fieldNames;
}
 
Example #2
Source File: AssociationOutputTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@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: DefaultChildTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 #4
Source File: MLModelRegistryService.java    From registry with Apache License 2.0 6 votes vote down vote up
private List<MLModelField> doGetOutputFieldsForPMMLStream(String pmmlContents) throws SAXException, JAXBException {
    List<MLModelField> fieldNames = new ArrayList<>();
    PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes())));
    Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
    modelEvaluator.getPredictedFields().forEach((f) -> fieldNames.add(getModelField(modelEvaluator.getDataField(f))));

    modelEvaluator.getOutputFields().forEach((f) -> {
        OutputField outputField = modelEvaluator.getOutputField(f);
        ResultFeatureType resultFeatureType = outputField.getFeature();
        if (resultFeatureType != ResultFeatureType.PREDICTED_VALUE &&
                resultFeatureType != ResultFeatureType.PREDICTED_DISPLAY_VALUE) {
            fieldNames.add(getModelField(outputField));
        }
    });

    return fieldNames;
}
 
Example #5
Source File: MLModelRegistryService.java    From registry with Apache License 2.0 5 votes vote down vote up
private List<MLModelField> doGetInputFieldsFromPMMLStream(String pmmlContents) throws SAXException, JAXBException {
    final List<MLModelField> fieldNames = new ArrayList<>();
    PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes())));
    Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
    for (FieldName predictedField : modelEvaluator.getActiveFields()) {
        fieldNames.add(getModelField(modelEvaluator.getDataField(predictedField)));
    }
    return fieldNames;
}
 
Example #6
Source File: TransformationDictionaryTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
private FieldValue evaluate(FieldName name, Map<FieldName, ?> arguments) throws Exception {
	ModelEvaluator<?> evaluator = createModelEvaluator();

	ModelEvaluationContext context = evaluator.createEvaluationContext();
	context.setArguments(arguments);

	return context.evaluate(name);
}
 
Example #7
Source File: ClusteringNeighborhoodTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #8
Source File: ContrastMatrixTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #9
Source File: ModelChainCompositionTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void getResultFields() throws Exception {
	ModelEvaluator<?> evaluator = createModelEvaluator();

	assertFalse(evaluator.hasResultFeature(ResultFeature.ENTITY_ID));
	assertTrue(evaluator.hasResultFeature(ResultFeature.TRANSFORMED_VALUE));

	checkResultFields(Arrays.asList("Class", "PollenIndex"), Arrays.asList("Setosa Pollen Index", "Versicolor Pollen Index", "Virginica Pollen Index", "Pollen Index", "Segment Id", "Class Node", "Class Score", "Class Score Code"), evaluator);
}
 
Example #10
Source File: ModelNestingTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #11
Source File: MissingPredictionTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #12
Source File: MiningModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
private ModelEvaluator<?> ensureSegmentModelEvaluator(String segmentId, Model model){
	ModelEvaluator<?> segmentModelEvaluator = this.segmentModelEvaluators.get(segmentId);

	if(segmentModelEvaluator == null){
		segmentModelEvaluator = createSegmentModelEvaluator(segmentId, model);

		this.segmentModelEvaluators.putIfAbsent(segmentId, segmentModelEvaluator);
	}

	return segmentModelEvaluator;
}
 
Example #13
Source File: MiningModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
private List<OutputField> createNestedOutputFields(List<Segment> segments){
	List<OutputField> result = new ArrayList<>();

	BiMap<String, Segment> entityRegistry = getEntityRegistry();

	for(int i = 0, max = segments.size(); i < max; i++){
		Segment segment = segments.get(i);

		Model model = segment.getModel();
		if(model == null){
			throw new MissingElementException(MissingElementException.formatMessage(XPathUtil.formatElement(segment.getClass()) + "/<Model>"), segment);
		}

		String segmentId = EntityUtil.getId(segment, entityRegistry);

		ModelEvaluator<?> segmentModelEvaluator = ensureSegmentModelEvaluator(segmentId, model);

		List<OutputField> outputFields = segmentModelEvaluator.getOutputFields();
		for(OutputField outputField : outputFields){
			OutputField nestedOutputField = new OutputField(outputField.getField(), outputField.getDepth() + 1);

			result.add(nestedOutputField);
		}
	}

	return ImmutableList.copyOf(result);
}
 
Example #14
Source File: MLModelRegistryService.java    From streamline with Apache License 2.0 5 votes vote down vote up
private List<MLModelField> doGetInputFieldsFromPMMLStream(String pmmlContents) throws SAXException, JAXBException, UnsupportedEncodingException {
    final List<MLModelField> fieldNames = new ArrayList<>();
    PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes("UTF-8"))));
    Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
    for (FieldName predictedField: modelEvaluator.getActiveFields()) {
        fieldNames.add(getModelField(modelEvaluator.getDataField(predictedField)));
    }
    return fieldNames;
}
 
Example #15
Source File: RankingTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@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 #16
Source File: ScalarVerificationTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@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 #17
Source File: SegmentResult.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public List<OutputField> getOutputFields(){
	ModelEvaluator<?> modelEvaluator = getModelEvaluator();

	return modelEvaluator.getOutputFields();
}
 
Example #18
Source File: EmptyTargetCategoryTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@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 #19
Source File: SegmentResult.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public List<TargetField> getTargetFields(){
	ModelEvaluator<?> modelEvaluator = getModelEvaluator();

	return modelEvaluator.getTargetFields();
}
 
Example #20
Source File: MultiTargetTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@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 #21
Source File: SegmentResult.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
abstract
protected ModelEvaluator<?> getModelEvaluator();
 
Example #22
Source File: MiningModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
private ModelEvaluator<?> createSegmentModelEvaluator(String segmentId, Model model){
	MiningModel miningModel = getModel();

	MiningFunction miningFunction = miningModel.getMiningFunction();

	Segmentation segmentation = miningModel.getSegmentation();

	Configuration configuration = ensureConfiguration();

	ModelEvaluatorFactory modelEvaluatorFactory = configuration.getModelEvaluatorFactory();

	ModelEvaluator<?> modelEvaluator = modelEvaluatorFactory.newModelEvaluator(getPMML(), model);

	Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
	switch(multipleModelMethod){
		case SELECT_FIRST:
		case SELECT_ALL:
		case MODEL_CHAIN:
			{
				Set<ResultFeature> resultFeatures = getResultFeatures();

				if(!resultFeatures.isEmpty()){
					modelEvaluator.addResultFeatures(resultFeatures);
				}
			}
			// Falls through
		default:
			{
				Set<ResultFeature> segmentResultFeatures = getSegmentResultFeatures(segmentId);

				if(segmentResultFeatures != null && !segmentResultFeatures.isEmpty()){
					modelEvaluator.addResultFeatures(segmentResultFeatures);
				}
			}
			break;
	}

	MiningFunction segmentMiningFunction = model.getMiningFunction();

	if((MiningFunction.CLASSIFICATION).equals(miningFunction) && (MiningFunction.CLASSIFICATION).equals(segmentMiningFunction)){
		List<TargetField> targetFields = getTargetFields();
		List<TargetField> segmentTargetFields = modelEvaluator.getTargetFields();

		if(targetFields.size() == 1 && segmentTargetFields.size() == 1){
			TargetField targetField = targetFields.get(0);
			TargetField segmentTargetField = segmentTargetFields.get(0);

			if(segmentTargetField instanceof DefaultTargetField){
				DefaultTargetField defaultTargetField = (DefaultTargetField)segmentTargetField;

				modelEvaluator.setDefaultDataField(new DataField(Evaluator.DEFAULT_TARGET_NAME, OpType.CATEGORICAL, targetField.getDataType()));
			}
		}
	}

	modelEvaluator.configure(configuration);

	return modelEvaluator;
}
 
Example #23
Source File: ModelChainSimpleTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void getResultFields() throws Exception {
	ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

	Configuration configuration = configurationBuilder.build();

	ModelEvaluator<?> evaluator = createModelEvaluator(configuration);

	checkResultFields(Arrays.asList("Class", "PollenIndex"), Arrays.asList("Pollen Index"), evaluator);

	configurationBuilder.setOutputFilter(OutputFilters.KEEP_FINAL_RESULTS);

	configuration = configurationBuilder.build();

	evaluator.configure(configuration);

	checkResultFields(Arrays.asList("Class", "PollenIndex"), Arrays.asList(), evaluator);
}
 
Example #24
Source File: CategoricalResidualTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@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 #25
Source File: DefaultValueTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 3 votes vote down vote up
@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 #26
Source File: PriorProbabilitiesTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 3 votes vote down vote up
@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 #27
Source File: RegressionOutputTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 3 votes vote down vote up
@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 #28
Source File: ContinuousResidualTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 3 votes vote down vote up
@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 #29
Source File: VectorInstanceTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 3 votes vote down vote up
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 #30
Source File: AlternateBinaryTargetCategoryTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 3 votes vote down vote up
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();
}