Java Code Examples for org.dmg.pmml.DataField#getName()
The following examples show how to use
org.dmg.pmml.DataField#getName() .
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: Transformer.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 6 votes |
public DataField updateDataField(DataField dataField, OpType opType, DataType dataType, SkLearnEncoder encoder){ FieldName name = dataField.getName(); if(encoder.isFrozen(name)){ return dataField; } switch(dataType){ case DOUBLE: // If the DataField element already specifies a non-default data type, then keep it if(!(DataType.DOUBLE).equals(dataField.getDataType())){ dataType = dataField.getDataType(); } break; } dataField .setOpType(opType) .setDataType(dataType); return dataField; }
Example 2
Source File: Domain.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 6 votes |
@Override public DataField updateDataField(DataField dataField, OpType opType, DataType dataType, SkLearnEncoder encoder){ FieldName name = dataField.getName(); if(encoder.isFrozen(name)){ throw new IllegalArgumentException("Field " + name.getValue() + " is frozen for type information updates"); } dataField .setDataType(dataType) .setOpType(opType); encoder.setDomain(name, this); return dataField; }
Example 3
Source File: CategoricalDomain.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 5 votes |
@Override public Feature encode(WildcardFeature wildcardFeature, List<?> values){ PMMLEncoder encoder = wildcardFeature.getEncoder(); if(values == null || values.isEmpty()){ DataField dataField = (DataField)encoder.getField(wildcardFeature.getName()); dataField.setOpType(OpType.CATEGORICAL); return new ObjectFeature(encoder, dataField.getName(), dataField.getDataType()); } return wildcardFeature.toCategoricalFeature(standardizeValues(wildcardFeature.getDataType(), values)); }
Example 4
Source File: TemporalDomain.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 4 votes |
@Override public List<Feature> encodeFeatures(List<Feature> features, SkLearnEncoder encoder){ features = super.encodeFeatures(features, encoder); List<Feature> result = new ArrayList<>(); for(int i = 0; i < features.size(); i++){ Feature feature = features.get(i); WildcardFeature wildcardFeature = asWildcardFeature(feature); DataField dataField = wildcardFeature.getField(); dataField.setOpType(OpType.ORDINAL); feature = new ObjectFeature(encoder, dataField.getName(), dataField.getDataType()); result.add(feature); } return result; }
Example 5
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 6
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()); }