org.dmg.pmml.Header Java Examples
The following examples show how to use
org.dmg.pmml.Header.
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: MarshallerTest.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void marshal() throws Exception { PMML pmml = new PMML(Version.PMML_4_4.getVersion(), new Header(), new DataDictionary()); JAXBContext context = ContextFactory.createContext(new Class[]{org.dmg.pmml.ObjectFactory.class}, null); Marshaller marshaller = context.createMarshaller(); String string; try(ByteArrayOutputStream os = new ByteArrayOutputStream()){ marshaller.marshal(pmml, os); string = os.toString("UTF-8"); } assertTrue(string.contains("<PMML xmlns=\"http://www.dmg.org/PMML-4_4\"")); assertTrue(string.contains(" version=\"4.4\">")); assertTrue(string.contains("</PMML>")); }
Example #2
Source File: TargetUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 6 votes |
static private TreeModelEvaluator createTreeModelEvaluator(MiningFunction miningFunction, MathContext mathContext, Target target){ Node root = new LeafNode(null, False.INSTANCE); Targets targets = new Targets() .addTargets(target); TreeModel treeModel = new TreeModel(miningFunction, new MiningSchema(), root) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT) .setMathContext(mathContext) .setTargets(targets); PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), new DataDictionary()) .addModels(treeModel); ModelEvaluatorBuilder modelEvaluatorBuilder = new ModelEvaluatorBuilder(pmml); return (TreeModelEvaluator)modelEvaluatorBuilder.build(); }
Example #3
Source File: PMMLUtils.java From oryx with Apache License 2.0 | 5 votes |
/** * @return {@link PMML} with common {@link Header} fields like {@link Application}, * {@link Timestamp}, and version filled out */ public static PMML buildSkeletonPMML() { String formattedDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZ", Locale.ENGLISH).format(new Date()); Header header = new Header() .setTimestamp(new Timestamp().addContent(formattedDate)) .setApplication(new Application("Oryx")); return new PMML(VERSION, header, null); }
Example #4
Source File: ReflectionUtilTest.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void copyState(){ PMML pmml = new PMML(Version.PMML_4_4.getVersion(), new Header(), new DataDictionary()); // Initialize a live list instance pmml.getModels(); CustomPMML customPmml = new CustomPMML(); ReflectionUtil.copyState(pmml, customPmml); assertSame(pmml.getVersion(), customPmml.getVersion()); assertSame(pmml.getHeader(), customPmml.getHeader()); assertSame(pmml.getDataDictionary(), customPmml.getDataDictionary()); assertFalse(pmml.hasModels()); assertFalse(customPmml.hasModels()); pmml.addModels(new RegressionModel()); assertTrue(pmml.hasModels()); assertTrue(customPmml.hasModels()); assertSame(pmml.getModels(), customPmml.getModels()); try { ReflectionUtil.copyState(customPmml, pmml); fail(); } catch(IllegalArgumentException iae){ // Ignored } }
Example #5
Source File: VersionInspectorTest.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 5 votes |
static private PMML createPMML(){ Header header = new Header() .setCopyright("ACME Corporation"); DataDictionary dataDictionary = new DataDictionary(); PMML pmml = new PMML(Version.PMML_4_4.getVersion(), header, dataDictionary); return pmml; }
Example #6
Source File: MarshallerTest.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void marshal() throws Exception { PMML pmml = new PMML(Version.PMML_4_4.getVersion(), new Header(), new DataDictionary()); RegressionModel regressionModel = new RegressionModel() .addRegressionTables(new RegressionTable()); pmml.addModels(regressionModel); JAXBContext context = JAXBContextFactory.createContext(new Class[]{org.dmg.pmml.ObjectFactory.class, org.dmg.pmml.regression.ObjectFactory.class}, null); Marshaller marshaller = context.createMarshaller(); String string; try(ByteArrayOutputStream os = new ByteArrayOutputStream()){ marshaller.marshal(pmml, os); string = os.toString("UTF-8"); } assertTrue(string.contains("<PMML xmlns=\"http://www.dmg.org/PMML-4_4\"")); assertTrue(string.contains(" version=\"4.4\">")); assertTrue(string.contains("<RegressionModel>")); assertTrue(string.contains("</RegressionModel>")); assertTrue(string.contains("</PMML>")); }
Example #7
Source File: NodeResolverTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Test public void resolve(){ Node leftChild = new LeafNode() .setId("1"); Node rightChild = new LeafNode() .setId("2"); Node root = new BranchNode(null, True.INSTANCE) .setId("0") .setDefaultChild(rightChild.getId()) .addNodes(leftChild, rightChild); TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, new MiningSchema(), null) .setNode(root); PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), new DataDictionary()) .addModels(treeModel); NodeResolver resolver = new NodeResolver(); resolver.applyTo(pmml); assertEquals(rightChild.getId(), root.getDefaultChild()); treeModel.setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD); resolver.applyTo(pmml); assertSame(rightChild, root.getDefaultChild()); }
Example #8
Source File: UnsupportedMarkupInspectorTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Test public void inspect(){ ClusteringModel clusteringModel = new ClusteringModel() .setModelClass(ClusteringModel.ModelClass.DISTRIBUTION_BASED) .setCenterFields(new CustomCenterFields()); PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), new DataDictionary()) .addModels(clusteringModel); UnsupportedMarkupInspector inspector = new UnsupportedMarkupInspector(); try { inspector.applyTo(pmml); fail(); } catch(UnsupportedMarkupException ume){ List<UnsupportedMarkupException> exceptions = inspector.getExceptions(); assertEquals(2, exceptions.size()); assertEquals(0, exceptions.indexOf(ume)); UnsupportedMarkupException exception = exceptions.get(0); String message = exception.getMessage(); assertTrue(message.contains("ClusteringModel@modelClass=distributionBased")); exception = exceptions.get(1); message = exception.getMessage(); assertTrue(message.contains("CenterFields")); assertTrue(message.contains(CustomCenterFields.class.getName())); } }
Example #9
Source File: AbstractAppMLlibIT.java From oryx with Apache License 2.0 | 4 votes |
protected static void checkHeader(Header header) { assertNotNull(header); assertNotNull(header.getTimestamp()); assertEquals("Oryx", header.getApplication().getName()); }
Example #10
Source File: GolfingTreeModelExample.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public PMML produce(){ FieldName temperature = FieldName.create("temperature"); FieldName humidity = FieldName.create("humidity"); FieldName windy = FieldName.create("windy"); FieldName outlook = FieldName.create("outlook"); FieldName whatIdo = FieldName.create("whatIDo"); Header header = new Header() .setCopyright("www.dmg.org") .setDescription("A very small binary tree model to show structure."); DataDictionary dataDictionary = new DataDictionary() .addDataFields( new DataField(temperature, OpType.CONTINUOUS, DataType.DOUBLE), new DataField(humidity, OpType.CONTINUOUS, DataType.DOUBLE), new DataField(windy, OpType.CATEGORICAL, DataType.STRING) .addValues(createValues("true", "false")), new DataField(outlook, OpType.CATEGORICAL, DataType.STRING) .addValues(createValues("sunny", "overcast", "rain")), new DataField(whatIdo, OpType.CATEGORICAL, DataType.STRING) .addValues(createValues("will play", "may play", "no play")) ); dataDictionary.setNumberOfFields((dataDictionary.getDataFields()).size()); MiningSchema miningSchema = new MiningSchema() .addMiningFields( new MiningField(temperature), new MiningField(humidity), new MiningField(windy), new MiningField(outlook), new MiningField(whatIdo) .setUsageType(MiningField.UsageType.TARGET) ); Node root = new BranchNode("will play", True.INSTANCE); // Upper half of the tree root.addNodes( new BranchNode("will play", new SimplePredicate(outlook, Operator.EQUAL, "sunny")) .addNodes( new BranchNode("will play", createCompoundPredicate(BooleanOperator.AND, new SimplePredicate(temperature, Operator.LESS_THAN, "90"), new SimplePredicate(temperature, Operator.GREATER_THAN, "50")) ) .addNodes( new LeafNode("will play", new SimplePredicate(humidity, Operator.LESS_THAN, "80")), new LeafNode("no play", new SimplePredicate(humidity, Operator.GREATER_OR_EQUAL, "80")) ), new LeafNode("no play", createCompoundPredicate(BooleanOperator.OR, new SimplePredicate(temperature, Operator.GREATER_OR_EQUAL, "90"), new SimplePredicate(temperature, Operator.LESS_OR_EQUAL, "50")) ) ) ); // Lower half of the tree root.addNodes( new BranchNode("may play", createCompoundPredicate(BooleanOperator.OR, new SimplePredicate(outlook, Operator.EQUAL, "overcast"), new SimplePredicate(outlook, Operator.EQUAL, "rain")) ) .addNodes( new LeafNode("may play", createCompoundPredicate(BooleanOperator.AND, new SimplePredicate(temperature, Operator.GREATER_THAN, "60"), new SimplePredicate(temperature, Operator.LESS_THAN, "100"), new SimplePredicate(outlook, Operator.EQUAL, "overcast"), new SimplePredicate(humidity, Operator.LESS_THAN, "70"), new SimplePredicate(windy, Operator.EQUAL, "false")) ), new LeafNode("no play", createCompoundPredicate(BooleanOperator.AND, new SimplePredicate(outlook, Operator.EQUAL, "rain"), new SimplePredicate(humidity, Operator.LESS_THAN, "70")) ) ) ); TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, miningSchema, root) .setModelName("golfing"); PMML pmml = new PMML(Version.PMML_4_4.getVersion(), header, dataDictionary) .addModels(treeModel); return pmml; }
Example #11
Source File: HasNodeRegistryTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Test public void getPath(){ Node node1a = new BranchNode(); Node node2a = new BranchNode(); Node node2b = new BranchNode(); node1a.addNodes(node2a, node2b); Node node3a = new BranchNode(); Node node3b = new BranchNode(); node2a.addNodes(node3a, node3b); Node node3c = new LeafNode(); Node node3d = new LeafNode(); node2b.addNodes(node3c, node3d); PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), new DataDictionary()) .addModels(new TreeModel(MiningFunction.REGRESSION, new MiningSchema(), node1a)); HasNodeRegistry hasNodeRegistry = new TreeModelEvaluator(pmml); BiMap<Node, String> nodeRegistry = (hasNodeRegistry.getEntityRegistry()).inverse(); String id1a = nodeRegistry.get(node1a); String id2a = nodeRegistry.get(node2a); String id2b = nodeRegistry.get(node2b); String id3a = nodeRegistry.get(node3a); String id3b = nodeRegistry.get(node3b); String id3c = nodeRegistry.get(node3c); String id3d = nodeRegistry.get(node3d); assertEquals(Arrays.asList(node1a), hasNodeRegistry.getPath(id1a)); assertEquals(Arrays.asList(node1a, node2a), hasNodeRegistry.getPath(id2a)); assertEquals(Arrays.asList(node1a, node2a, node3a), hasNodeRegistry.getPath(id3a)); assertEquals(Arrays.asList(node1a), hasNodeRegistry.getPathBetween(id1a, id1a)); assertEquals(Arrays.asList(node1a, node2a), hasNodeRegistry.getPathBetween(id1a, id2a)); assertNull(hasNodeRegistry.getPathBetween(id2a, id1a)); assertEquals(Arrays.asList(node2a, node3a), hasNodeRegistry.getPathBetween(id2a, id3a)); assertEquals(Arrays.asList(node2a, node3b), hasNodeRegistry.getPathBetween(id2a, id3b)); assertNull(hasNodeRegistry.getPathBetween(id2a, id2b)); assertNull(hasNodeRegistry.getPathBetween(id2a, id3c)); assertNull(hasNodeRegistry.getPathBetween(id2a, id3d)); }
Example #12
Source File: ValueParserTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Test public void parseRegressionModel(){ Value falseValue = new Value("false"); Value trueValue = new Value("true"); Value invalidValue = new Value("N/A"); DataField dataField = new DataField(FieldName.create("x1"), OpType.CATEGORICAL, DataType.STRING) .addValues(falseValue, trueValue, invalidValue); DataDictionary dataDictionary = new DataDictionary() .addDataFields(dataField); CategoricalPredictor falseTerm = new CategoricalPredictor(dataField.getName(), "false", -1d); CategoricalPredictor trueTerm = new CategoricalPredictor(dataField.getName(), "true", 1d); RegressionTable regressionTable = new RegressionTable() .addCategoricalPredictors(falseTerm, trueTerm); MiningField miningField = new MiningField(dataField.getName()) .setMissingValueReplacement("false") .setInvalidValueReplacement("N/A"); MiningSchema miningSchema = new MiningSchema() .addMiningFields(miningField); RegressionModel regressionModel = new RegressionModel(MiningFunction.REGRESSION, miningSchema, null) .addRegressionTables(regressionTable); PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), dataDictionary) .addModels(regressionModel); List<DataField> dataFields = dataDictionary.getDataFields(); ValueParser parser = new ValueParser(ValueParser.Mode.STRICT); parser.applyTo(pmml); dataField = dataFields.get(0); assertEquals("false", falseValue.getValue()); assertEquals("true", trueValue.getValue()); assertEquals("N/A", invalidValue.getValue()); assertEquals("false", falseTerm.getValue()); assertEquals("true", trueTerm.getValue()); assertEquals("false", miningField.getMissingValueReplacement()); assertEquals("N/A", miningField.getInvalidValueReplacement()); dataField.setDataType(DataType.BOOLEAN); parser.applyTo(pmml); assertEquals(Boolean.FALSE, falseValue.getValue()); assertEquals(Boolean.TRUE, trueValue.getValue()); assertEquals("N/A", invalidValue.getValue()); assertEquals(Boolean.FALSE, falseTerm.getValue()); assertEquals(Boolean.TRUE, trueTerm.getValue()); assertEquals(Boolean.FALSE, miningField.getMissingValueReplacement()); assertEquals("N/A", miningField.getInvalidValueReplacement()); }
Example #13
Source File: ModelManagerFactoryTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Test public void newModelManager(){ ModelManagerFactory<ModelManager<?>> modelManagerFactory = new ModelManagerFactory<ModelManager<?>>(null){ @Override public List<Class<? extends ModelManager<?>>> getServiceProviderClasses(Class<? extends Model> modelClazz){ return Arrays.asList(RegressorManager.class, ClassifierManager.class); } }; TreeModel treeModel = new TreeModel() .setMiningFunction(null) .setMiningSchema(new MiningSchema()); PMML pmml = new PMML() .setHeader(new Header()) .setDataDictionary(new DataDictionary()) .addModels(treeModel); ModelManager<?> modelManager; try { modelManager = modelManagerFactory.newModelManager(pmml, treeModel); fail(); } catch(InvalidMarkupException ime){ // Ignored } treeModel.setMiningFunction(MiningFunction.REGRESSION); modelManager = modelManagerFactory.newModelManager(pmml, treeModel); assertTrue(modelManager instanceof RegressorManager); treeModel.setMiningFunction(MiningFunction.CLASSIFICATION); modelManager = modelManagerFactory.newModelManager(pmml, treeModel); assertTrue(modelManager instanceof ClassifierManager); }
Example #14
Source File: ValueParserTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 2 votes |
@Test public void parseTreeModel(){ DataField dataField = new DataField(FieldName.create("x1"), OpType.CATEGORICAL, DataType.STRING); DataDictionary dataDictionary = new DataDictionary() .addDataFields(dataField); NormDiscrete normDiscrete = new NormDiscrete(dataField.getName(), "1"); DerivedField derivedField = new DerivedField(FieldName.create("global(" + dataField.getName() + ")"), OpType.CATEGORICAL, DataType.STRING, normDiscrete); TransformationDictionary transformationDictionary = new TransformationDictionary() .addDerivedFields(derivedField); SimplePredicate simplePredicate = new SimplePredicate(derivedField.getName(), SimplePredicate.Operator.EQUAL, "1"); Node child = new LeafNode("1", simplePredicate); SimpleSetPredicate simpleSetPredicate = new SimpleSetPredicate(dataField.getName(), SimpleSetPredicate.BooleanOperator.IS_IN, new Array(Array.Type.STRING, "0 1")); Node root = new BranchNode("0", simpleSetPredicate) .addNodes(child); MiningField miningField = new MiningField(dataField.getName()); MiningSchema miningSchema = new MiningSchema() .addMiningFields(miningField); TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, miningSchema, null) .setNode(root); PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), dataDictionary) .setTransformationDictionary(transformationDictionary) .addModels(treeModel); List<DataField> dataFields = dataDictionary.getDataFields(); ValueParser parser = new ValueParser(ValueParser.Mode.STRICT); parser.applyTo(pmml); dataField = dataFields.get(0); assertEquals("1", normDiscrete.getValue()); assertEquals("1", simplePredicate.getValue()); Array array = simpleSetPredicate.getArray(); assertEquals(ImmutableSet.of("0", "1"), array.getValue()); dataField.setDataType(DataType.INTEGER); parser.applyTo(pmml); dataField = dataFields.get(0); assertEquals(1, normDiscrete.getValue()); assertEquals("1", simplePredicate.getValue()); array = simpleSetPredicate.getArray(); assertTrue(array instanceof RichComplexArray); assertEquals(ImmutableSet.of(0, 1), array.getValue()); dataField.setDataType(DataType.DOUBLE); derivedField.setDataType(DataType.INTEGER); parser.applyTo(pmml); dataField = dataFields.get(0); assertEquals(1.0d, normDiscrete.getValue()); assertEquals(1, simplePredicate.getValue()); array = simpleSetPredicate.getArray(); assertEquals(ImmutableSet.of(0.0d, 1.0d), array.getValue()); dataField.setDataType(DataType.BOOLEAN); derivedField.setDataType(DataType.DOUBLE); parser.applyTo(pmml); dataField = dataFields.get(0); assertEquals(true, normDiscrete.getValue()); assertEquals(1.0d, simplePredicate.getValue()); array = simpleSetPredicate.getArray(); assertEquals(ImmutableSet.of(false, true), array.getValue()); derivedField.setDataType(DataType.BOOLEAN); parser.applyTo(pmml); dataField = dataFields.get(0); assertEquals(true, normDiscrete.getValue()); assertEquals(true, simplePredicate.getValue()); }