Java Code Examples for org.dmg.pmml.mining.Segmentation#getSegments()

The following examples show how to use org.dmg.pmml.mining.Segmentation#getSegments() . 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: MiningModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<OutputField> createNestedOutputFields(){
	MiningModel miningModel = getModel();

	Segmentation segmentation = miningModel.getSegmentation();

	List<Segment> segments = segmentation.getSegments();

	Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
	switch(multipleModelMethod){
		case SELECT_FIRST:
			return createNestedOutputFields(getActiveHead(segments));
		case SELECT_ALL:
			// Ignored
			break;
		case MODEL_CHAIN:
			return createNestedOutputFields(getActiveTail(segments));
		default:
			break;
	}

	return Collections.emptyList();
}
 
Example 2
Source File: FieldResolver.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static
private List<Output> getEarlierOutputs(Segmentation segmentation, Segment targetSegment){
	List<Output> result = new ArrayList<>();

	Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
	switch(multipleModelMethod){
		case MODEL_CHAIN:
			break;
		default:
			return Collections.emptyList();
	}

	List<Segment> segments = segmentation.getSegments();
	for(Segment segment : segments){
		Model model = segment.getModel();

		if(targetSegment != null && (targetSegment).equals(segment)){
			break;
		}

		Output output = model.getOutput();
		if(output != null){
			result.add(output);
		}
	}

	return result;
}
 
Example 3
Source File: MiningModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
public MiningModelEvaluator(PMML pmml, MiningModel miningModel){
	super(pmml, miningModel);

	if(miningModel.hasEmbeddedModels()){
		List<EmbeddedModel> embeddedModels = miningModel.getEmbeddedModels();

		EmbeddedModel embeddedModel = Iterables.getFirst(embeddedModels, null);

		throw new UnsupportedElementException(embeddedModel);
	}

	Segmentation segmentation = miningModel.getSegmentation();
	if(segmentation == null){
		throw new MissingElementException(miningModel, PMMLElements.MININGMODEL_SEGMENTATION);
	}

	Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
	if(multipleModelMethod == null){
		throw new MissingAttributeException(segmentation, PMMLAttributes.SEGMENTATION_MULTIPLEMODELMETHOD);
	} // End if

	if(!segmentation.hasSegments()){
		throw new MissingElementException(segmentation, PMMLElements.SEGMENTATION_SEGMENTS);
	}

	List<Segment> segments = segmentation.getSegments();
	for(Segment segment : segments){
		VariableWeight variableWeight = segment.getVariableWeight();

		if(variableWeight != null){
			throw new UnsupportedElementException(variableWeight);
		}
	}

	LocalTransformations localTransformations = segmentation.getLocalTransformations();
	if(localTransformations != null){
		throw new UnsupportedElementException(localTransformations);
	}

	Output output = miningModel.getOutput();
	if(output != null && output.hasOutputFields()){
		this.segmentResultFeatures = CacheUtil.getValue(output, MiningModelEvaluator.segmentResultFeaturesCache);
	}
}
 
Example 4
Source File: MissingPredictionTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void evaluate() throws Exception {
	MiningModelEvaluator evaluator = (MiningModelEvaluator)createModelEvaluator();

	MiningModel miningModel = evaluator.getModel();

	Segmentation segmentation = miningModel.getSegmentation();

	assertEquals(null, evaluate(evaluator, null));

	segmentation.setMissingThreshold(0.25);

	assertEquals(null, evaluate(evaluator, 0d));
	assertEquals(null, evaluate(evaluator, 1d));
	assertEquals(null, evaluate(evaluator, 2d));
	assertEquals((Integer)1, evaluate(evaluator, 3d));
	assertEquals((Integer)1, evaluate(evaluator, 4d));

	segmentation.setMissingThreshold(0.5d);

	assertEquals(null, evaluate(evaluator, 1d));
	assertEquals((Integer)1, evaluate(evaluator, 2d));
	assertEquals((Integer)1, evaluate(evaluator, 3d));

	segmentation.setMissingThreshold(0.75d);

	// Two votes for the missing pseudo-category vs. one vote for the "1" category
	assertEquals(null, evaluate(evaluator, 1d));

	assertEquals((Integer)1, evaluate(evaluator, 2d));
	assertEquals((Integer)1, evaluate(evaluator, 3d));

	List<Segment> segments = segmentation.getSegments();
	for(Segment segment : segments){
		TreeModel treeModel = (TreeModel)segment.getModel();

		treeModel.setNoTrueChildStrategy(TreeModel.NoTrueChildStrategy.RETURN_LAST_PREDICTION);
	}

	assertEquals(null, evaluate(evaluator, null));

	assertEquals((Integer)0, evaluate(evaluator, 1d));
	assertEquals((Integer)1, evaluate(evaluator, 2d));
	assertEquals((Integer)1, evaluate(evaluator, 3d));
}