Java Code Examples for org.dmg.pmml.DataType#DOUBLE
The following examples show how to use
org.dmg.pmml.DataType#DOUBLE .
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: DatasetUtil.java From jpmml-sparkml with GNU Affero General Public License v3.0 | 6 votes |
static public DataType translateDataType(org.apache.spark.sql.types.DataType sparkDataType){ if(sparkDataType instanceof StringType){ return DataType.STRING; } else if(sparkDataType instanceof IntegralType){ return DataType.INTEGER; } else if(sparkDataType instanceof DoubleType){ return DataType.DOUBLE; } else if(sparkDataType instanceof BooleanType){ return DataType.BOOLEAN; } else { throw new IllegalArgumentException("Expected string, integral, double or boolean data type, got " + sparkDataType.typeName() + " data type"); } }
Example 2
Source File: Formula.java From jpmml-r with GNU Affero General Public License v3.0 | 6 votes |
public Feature resolveFeature(String name){ RExpEncoder encoder = getEncoder(); List<String> variables = split(name); if(variables.size() == 1){ return resolveFeature(FieldName.create(name)); } else { List<Feature> variableFeatures = new ArrayList<>(); for(String variable : variables){ Feature variableFeature = resolveFeature(FieldName.create(variable)); variableFeatures.add(variableFeature); } return new InteractionFeature(encoder, FieldName.create(name), DataType.DOUBLE, variableFeatures); } }
Example 3
Source File: RExpUtil.java From jpmml-r with GNU Affero General Public License v3.0 | 6 votes |
static public DataType getDataType(String type){ switch(type){ case "character": case "factor": return DataType.STRING; case "numeric": return DataType.DOUBLE; case "logical": return DataType.BOOLEAN; default: break; } throw new IllegalArgumentException(type); }
Example 4
Source File: TypeUtil.java From jpmml-tensorflow with GNU Affero General Public License v3.0 | 6 votes |
static public DataType getDataType(Output output){ org.tensorflow.DataType dataType = output.dataType(); switch(dataType){ case FLOAT: return DataType.FLOAT; case DOUBLE: return DataType.DOUBLE; case INT32: case INT64: return DataType.INTEGER; case STRING: return DataType.STRING; case BOOL: return DataType.BOOLEAN; default: throw new IllegalArgumentException(); } }
Example 5
Source File: ContinuousDomain.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 5 votes |
@Override public DataType getDataType(){ Object dtype = getDType(); if(dtype != null){ return TransformerUtil.getDataType(dtype); } return DataType.DOUBLE; }
Example 6
Source File: ExpressionTransformer.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 5 votes |
@Override public List<Feature> encodeFeatures(List<Feature> features, SkLearnEncoder encoder){ Object dtype = getDType(); String expr = getExpr(); Scope scope = new DataFrameScope(FieldName.create("X"), features); Expression expression = ExpressionTranslator.translate(expr, scope); DataType dataType; if(dtype != null){ dataType = TransformerUtil.getDataType(dtype); } else { if(ExpressionTranslator.isString(expression, scope)){ dataType = DataType.STRING; } else { dataType = DataType.DOUBLE; } } OpType opType = TransformerUtil.getOpType(dataType); DerivedField derivedField = encoder.createDerivedField(FieldName.create("eval(" + expr + ")"), opType, dataType, expression); return Collections.singletonList(new ContinuousFeature(encoder, derivedField)); }
Example 7
Source File: FunctionTransformerTest.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 5 votes |
static private Object evaluate(String function, Object value){ UFunc ufunc = new UFunc("numpy.core", "_ufunc_reconstruct"); ufunc.__init__(new String[]{"numpy", function}); FieldName name = FieldName.create("x"); DataType dataType; if(value instanceof Integer){ dataType = DataType.INTEGER; } else if(value instanceof Float){ dataType = DataType.FLOAT; } else { dataType = DataType.DOUBLE; } EvaluationContext context = new VirtualEvaluationContext(); context.declare(name, FieldValueUtil.create(dataType, OpType.CONTINUOUS, value)); Expression expression = UFuncUtil.encodeUFunc(ufunc, Collections.singletonList(new FieldRef(name))); FieldValue result = ExpressionUtil.evaluate(expression, context); return FieldValueUtil.getValue(result); }
Example 8
Source File: Formula.java From jpmml-r with GNU Affero General Public License v3.0 | 5 votes |
public void addField(Field<?> field){ RExpEncoder encoder = getEncoder(); Feature feature = new ContinuousFeature(encoder, field); if(field instanceof DerivedField){ DerivedField derivedField = (DerivedField)field; Expression expression = derivedField.getExpression(); if(expression instanceof Apply){ Apply apply = (Apply)expression; if(checkApply(apply, PMMLFunctions.POW, FieldRef.class, Constant.class)){ List<Expression> expressions = apply.getExpressions(); FieldRef fieldRef = (FieldRef)expressions.get(0); Constant constant = (Constant)expressions.get(1); try { String string = ValueUtil.asString(constant.getValue()); int power = Integer.parseInt(string); feature = new PowerFeature(encoder, fieldRef.getField(), DataType.DOUBLE, power); } catch(NumberFormatException nfe){ // Ignored } } } } putFeature(field.getName(), feature); this.fields.add(field); }
Example 9
Source File: AppPMMLUtils.java From oryx with Apache License 2.0 | 5 votes |
public static DataDictionary buildDataDictionary( InputSchema schema, CategoricalValueEncodings categoricalValueEncodings) { List<String> featureNames = schema.getFeatureNames(); List<DataField> dataFields = new ArrayList<>(); for (int featureIndex = 0; featureIndex < featureNames.size(); featureIndex++) { String featureName = featureNames.get(featureIndex); OpType opType; DataType dataType; if (schema.isNumeric(featureName)) { opType = OpType.CONTINUOUS; dataType = DataType.DOUBLE; } else if (schema.isCategorical(featureName)) { opType = OpType.CATEGORICAL; dataType = DataType.STRING; } else { // Don't know opType = null; dataType = null; } DataField field = new DataField(FieldName.create(featureName), opType, dataType); if (schema.isCategorical(featureName)) { Objects.requireNonNull(categoricalValueEncodings); categoricalValueEncodings.getEncodingValueMap(featureIndex).entrySet().stream(). sorted(Comparator.comparing(Map.Entry::getKey)). map(Map.Entry::getValue). forEach(value -> field.addValues(new Value(value))); } dataFields.add(field); } return new DataDictionary(dataFields).setNumberOfFields(dataFields.size()); }
Example 10
Source File: TypeUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
static public DataType getConstantDataType(String value){ if(("").equals(value)){ return DataType.STRING; } else if(("NaN").equalsIgnoreCase(value) || ("INF").equalsIgnoreCase(value) || ("-INF").equalsIgnoreCase(value)){ return DataType.DOUBLE; } try { if(value.indexOf('.') > -1){ Double.parseDouble(value); return DataType.DOUBLE; } else { Long.parseLong(value); return DataType.INTEGER; } } catch(NumberFormatException nfe){ return DataType.STRING; } }
Example 11
Source File: ContinuousValue.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
ContinuousDouble(Object value){ super(DataType.DOUBLE, value); Double doubleValue = (Double)getValue(); if(doubleValue.isNaN()){ setValid(false); } }
Example 12
Source File: Functions.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Override public DataType getResultDataType(DataType dataType){ if((DataType.INTEGER).equals(dataType)){ return DataType.DOUBLE; } return dataType; }
Example 13
Source File: Estimator.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 4 votes |
@Override public DataType getDataType(){ return DataType.DOUBLE; }
Example 14
Source File: RDoubleVector.java From jpmml-r with GNU Affero General Public License v3.0 | 4 votes |
@Override public DataType getDataType(){ return DataType.DOUBLE; }
Example 15
Source File: Transformer.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 4 votes |
@Override public DataType getDataType(){ return DataType.DOUBLE; }
Example 16
Source File: TargetFieldTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Test public void getName(){ FieldName name = FieldName.create("y"); DataField dataField = new DataField(name, OpType.CONTINUOUS, DataType.DOUBLE); TargetField targetField = new TargetField(dataField, null, null); assertEquals(name, targetField.getName()); targetField.setName(FieldName.create("label")); assertNotEquals(name, targetField.getName()); targetField.setName(null); assertEquals(name, targetField.getName()); }
Example 17
Source File: TargetFieldTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Test public void getOpType(){ FieldName name = FieldName.create("y"); DataField dataField = new DataField(name, OpType.CONTINUOUS, DataType.DOUBLE); MiningField miningField = new MiningField(name) .setOpType(OpType.CATEGORICAL); Target target = new Target() .setField(name) .setOpType(OpType.CONTINUOUS); TargetField targetField = new TargetField(dataField, null, null); assertEquals(OpType.CONTINUOUS, targetField.getOpType()); targetField = new TargetField(dataField, miningField, null); assertEquals(OpType.CATEGORICAL, targetField.getOpType()); targetField = new TargetField(dataField, miningField, target); assertEquals(OpType.CONTINUOUS, targetField.getOpType()); }
Example 18
Source File: InputFieldUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 3 votes |
@Test public void isDefault(){ FieldName name = FieldName.create("x"); DataField dataField = new DataField(name, OpType.CONTINUOUS, DataType.DOUBLE); MiningField miningField = new MiningField(name); assertTrue(InputFieldUtil.isDefault(dataField, miningField)); miningField.setOpType(OpType.CATEGORICAL); assertFalse(InputFieldUtil.isDefault(dataField, miningField)); }