Java Code Examples for org.dmg.pmml.DataField#addValues()
The following examples show how to use
org.dmg.pmml.DataField#addValues() .
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: AppPMMLUtilsTest.java From oryx with Apache License 2.0 | 6 votes |
@Test public void testBuildCategoricalEncoding() { List<DataField> dataFields = new ArrayList<>(); dataFields.add(new DataField(FieldName.create("foo"), OpType.CONTINUOUS, DataType.DOUBLE)); DataField barField = new DataField(FieldName.create("bar"), OpType.CATEGORICAL, DataType.STRING); barField.addValues(new Value("b"), new Value("a")); dataFields.add(barField); DataDictionary dictionary = new DataDictionary(dataFields).setNumberOfFields(dataFields.size()); CategoricalValueEncodings encodings = AppPMMLUtils.buildCategoricalValueEncodings(dictionary); assertEquals(2, encodings.getValueCount(1)); assertEquals(0, encodings.getValueEncodingMap(1).get("b").intValue()); assertEquals(1, encodings.getValueEncodingMap(1).get("a").intValue()); assertEquals("b", encodings.getEncodingValueMap(1).get(0)); assertEquals("a", encodings.getEncodingValueMap(1).get(1)); assertEquals(Collections.singletonMap(1, 2), encodings.getCategoryCounts()); }
Example 2
Source File: RDFPMMLUtilsTest.java From oryx with Apache License 2.0 | 4 votes |
private static PMML buildDummyClassificationModel(int numTrees) { PMML pmml = PMMLUtils.buildSkeletonPMML(); List<DataField> dataFields = new ArrayList<>(); DataField predictor = new DataField(FieldName.create("color"), OpType.CATEGORICAL, DataType.STRING); predictor.addValues(new Value("yellow"), new Value("red")); dataFields.add(predictor); DataField target = new DataField(FieldName.create("fruit"), OpType.CATEGORICAL, DataType.STRING); target.addValues(new Value("banana"), new Value("apple")); dataFields.add(target); DataDictionary dataDictionary = new DataDictionary(dataFields).setNumberOfFields(dataFields.size()); pmml.setDataDictionary(dataDictionary); List<MiningField> miningFields = new ArrayList<>(); MiningField predictorMF = new MiningField(FieldName.create("color")) .setOpType(OpType.CATEGORICAL) .setUsageType(MiningField.UsageType.ACTIVE) .setImportance(0.5); miningFields.add(predictorMF); MiningField targetMF = new MiningField(FieldName.create("fruit")) .setOpType(OpType.CATEGORICAL) .setUsageType(MiningField.UsageType.PREDICTED); miningFields.add(targetMF); MiningSchema miningSchema = new MiningSchema(miningFields); double dummyCount = 2.0; Node rootNode = new ComplexNode().setId("r").setRecordCount(dummyCount).setPredicate(new True()); double halfCount = dummyCount / 2; Node left = new ComplexNode().setId("r-").setRecordCount(halfCount).setPredicate(new True()); left.addScoreDistributions(new ScoreDistribution("apple", halfCount)); Node right = new ComplexNode().setId("r+").setRecordCount(halfCount) .setPredicate(new SimpleSetPredicate(FieldName.create("color"), SimpleSetPredicate.BooleanOperator.IS_NOT_IN, new Array(Array.Type.STRING, "red"))); right.addScoreDistributions(new ScoreDistribution("banana", halfCount)); rootNode.addNodes(right, left); TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, miningSchema, rootNode) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT) .setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD); if (numTrees > 1) { MiningModel miningModel = new MiningModel(MiningFunction.CLASSIFICATION, miningSchema); List<Segment> segments = new ArrayList<>(); for (int i = 0; i < numTrees; i++) { segments.add(new Segment() .setId(Integer.toString(i)) .setPredicate(new True()) .setModel(treeModel) .setWeight(1.0)); } miningModel.setSegmentation( new Segmentation(Segmentation.MultipleModelMethod.WEIGHTED_MAJORITY_VOTE, segments)); pmml.addModels(miningModel); } else { pmml.addModels(treeModel); } return pmml; }
Example 3
Source File: ReflectionUtilTest.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 2 votes |
@Test public void equals(){ DataField left = new DataField() .setName(FieldName.create("x")) .setCyclic(null); DataField right = new DataField() .setName(FieldName.create("x")) .setCyclic(DataField.Cyclic.ZERO); // Initialize a live list instance right.getValues(); assertTrue(ReflectionUtil.equals(left, right)); Value leftValue = new Value() .setValue(0) .setProperty(null); Value rightValue = new Value() .setValue(0) .setProperty(Value.Property.VALID); right.addValues(rightValue); assertFalse(ReflectionUtil.equals(left, right)); left.addValues(leftValue); assertTrue(ReflectionUtil.equals(left, right)); // Double != Integer leftValue.setValue(((Number)rightValue.getValue()).doubleValue()); assertFalse(ReflectionUtil.equals(left, right)); leftValue.setValue(rightValue.getValue()); assertTrue(ReflectionUtil.equals(left, right)); Value missingValue = new Value() .setValue(-999) .setProperty(Value.Property.MISSING); right.addValues(missingValue); assertFalse(ReflectionUtil.equals(left, right)); }