Java Code Examples for org.dmg.pmml.DataField#setDataType()
The following examples show how to use
org.dmg.pmml.DataField#setDataType() .
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: RichDataFieldTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Test public void getValueMapping(){ Value invalidValue = createValue("0", Value.Property.INVALID); Value validValueOne = createValue("1", Value.Property.VALID); Value validValueTwo = createValue("2", null); Value validValueThree = createValue("3", null); Value missingValue = createValue("N/A", Value.Property.MISSING); DataField dataField = new DataField(FieldName.create("x"), OpType.CATEGORICAL, DataType.STRING) .addValues(invalidValue, validValueOne, validValueTwo, validValueThree, missingValue); RichDataField richDataField = new RichDataField(dataField); Map<?, Integer> valueMap = richDataField.getMap(); assertEquals(5, valueMap.size()); assertEquals(FieldValue.STATUS_UNKNOWN_INVALID, valueMap.get("0")); assertEquals((Integer)1, valueMap.get("1")); assertEquals((Integer)2, valueMap.get("2")); assertEquals((Integer)3, valueMap.get("3")); assertEquals(FieldValue.STATUS_MISSING, valueMap.get("N/A")); dataField.setDataType(DataType.INTEGER); richDataField = new RichDataField(dataField); valueMap = richDataField.getMap(); assertEquals(4, valueMap.size()); assertEquals(FieldValue.STATUS_UNKNOWN_INVALID, valueMap.get(0)); assertEquals((Integer)1, valueMap.get(1)); assertEquals((Integer)2, valueMap.get(2)); assertEquals((Integer)3, valueMap.get(3)); }
Example 2
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 3
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()); }