本文整理汇总了Java中org.dmg.pmml.DataField类的典型用法代码示例。如果您正苦于以下问题:Java DataField类的具体用法?Java DataField怎么用?Java DataField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataField类属于org.dmg.pmml包,在下文中一共展示了DataField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBuildCategoricalEncoding
import org.dmg.pmml.DataField; //导入依赖的package包/类
@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());
}
示例2: createDataField
import org.dmg.pmml.DataField; //导入依赖的package包/类
public DataField createDataField(FieldName name){
StructField field = this.schema.apply(name.getValue());
org.apache.spark.sql.types.DataType sparkDataType = field.dataType();
if(sparkDataType instanceof StringType){
return createDataField(name, OpType.CATEGORICAL, DataType.STRING);
} else
if(sparkDataType instanceof IntegralType){
return createDataField(name, OpType.CONTINUOUS, DataType.INTEGER);
} else
if(sparkDataType instanceof DoubleType){
return createDataField(name, OpType.CONTINUOUS, DataType.DOUBLE);
} else
if(sparkDataType instanceof BooleanType){
return createDataField(name, OpType.CATEGORICAL, DataType.BOOLEAN);
} else
{
throw new IllegalArgumentException("Expected string, integral, double or boolean type, got " + sparkDataType.typeName() + " type");
}
}
示例3: getRawDataField
import org.dmg.pmml.DataField; //导入依赖的package包/类
public static DataField getRawDataField(DataDictionary dataDictionary, String rawFieldName) {
// now find the actual dataField
DataField rawField = null;
for (DataField dataField : dataDictionary.getDataFields()) {
String rawDataFieldName = dataField.getName().getValue();
if (rawDataFieldName.equals(rawFieldName)) {
rawField = dataField;
break;
}
}
if (rawField == null) {
throw new UnsupportedOperationException("Could not trace back {} to a raw input field. Maybe saomething is not implemented " +
"yet or the PMML file is faulty.");
}
return rawField;
}
示例4: getFieldValuesList
import org.dmg.pmml.DataField; //导入依赖的package包/类
protected static List<VectorRange> getFieldValuesList(TreeModel treeModel, DataDictionary dataDictionary,
TransformationDictionary transformationDictionary) {
// walk the tree model and gather all the field name
Set<String> fieldNames = new HashSet<>();
Node startNode = treeModel.getNode();
getFieldNamesFromNode(fieldNames, startNode);
// create the actual VectorRange objects, copy paste much from GLMHelper
List<VectorRange> fieldsToValues = new ArrayList<>();
List<DerivedField> allDerivedFields = ProcessPMMLHelper.getAllDerivedFields(treeModel, transformationDictionary);
for(String fieldName : fieldNames) {
List<DerivedField> derivedFields = new ArrayList<>();
String rawFieldName = ProcessPMMLHelper.getDerivedFields(fieldName, allDerivedFields, derivedFields);
DataField rawField = ProcessPMMLHelper.getRawDataField(dataDictionary, rawFieldName);
MiningField miningField = ProcessPMMLHelper.getMiningField(treeModel, rawFieldName);
fieldsToValues.add(new PMMLVectorRange.FieldToValue(rawField, miningField, derivedFields.toArray(new
DerivedField[derivedFields.size()])));
}
return fieldsToValues;
}
示例5: findTargetCategories
import org.dmg.pmml.DataField; //导入依赖的package包/类
private String[] findTargetCategories(DataDictionary dataDictionary, Map<String, List<PCell>> targetClassPCellMap,
String targetVariable) {
String[] targetCategories = new String[2];
String class1 = targetClassPCellMap.keySet().iterator().next();
targetCategories[0] = class1;
// find it in the datafields
for (DataField dataField : dataDictionary.getDataFields()) {
if (dataField.getName().toString().equals(targetVariable)) {
for (Value value : dataField.getValues()) {
String valueString = value.getValue();
if (valueString.equals(class1) == false) {
targetCategories[1] = valueString;
}
}
if (targetCategories[1] == null) {
throw new ElasticsearchParseException("could not find target class");
}
break;
}
}
return targetCategories;
}
示例6: getValues
import org.dmg.pmml.DataField; //导入依赖的package包/类
static
public List<String> getValues(DataField dataField, Value.Property property){
List<String> result = new ArrayList<>();
if(property == null){
property = Value.Property.VALID;
}
List<Value> pmmlValues = dataField.getValues();
for(Value pmmlValue : pmmlValues){
if((property).equals(pmmlValue.getProperty())){
result.add(pmmlValue.getValue());
}
}
return result;
}
示例7: wildcardFeature
import org.dmg.pmml.DataField; //导入依赖的package包/类
@Test
public void wildcardFeature(){
PMMLEncoder encoder = new PMMLEncoder();
DataField dataField = encoder.createDataField(FieldName.create("x"), OpType.CONTINUOUS, DataType.DOUBLE);
WildcardFeature wildcard = new WildcardFeature(encoder, dataField);
CategoricalFeature categoricalDouble = wildcard.toCategoricalFeature(Arrays.asList("1", "2", "3"));
assertEquals(DataType.DOUBLE, categoricalDouble.getDataType());
assertEquals(Arrays.asList("1", "2", "3"), categoricalDouble.getValues());
assertEquals(OpType.CATEGORICAL, dataField.getOpType());
assertEquals(DataType.DOUBLE, dataField.getDataType());
assertEquals(Arrays.asList("1", "2", "3"), PMMLUtil.getValues(dataField));
}
示例8: encodeSchema
import org.dmg.pmml.DataField; //导入依赖的package包/类
@Override
public void encodeSchema(RExpEncoder encoder){
RGenericVector glm = getObject();
RGenericVector family = (RGenericVector)glm.getValue("family");
RGenericVector model = (RGenericVector)glm.getValue("model");
RStringVector familyFamily = (RStringVector)family.getValue("family");
super.encodeSchema(encoder);
MiningFunction miningFunction = getMiningFunction(familyFamily.asScalar());
switch(miningFunction){
case CLASSIFICATION:
Label label = encoder.getLabel();
RIntegerVector variable = (RIntegerVector)model.getValue((label.getName()).getValue());
DataField dataField = (DataField)encoder.toCategorical(label.getName(), RExpUtil.getFactorLevels(variable));
encoder.setLabel(dataField);
break;
default:
break;
}
}
示例9: getDataField
import org.dmg.pmml.DataField; //导入依赖的package包/类
/**
* @return A synthetic {@link DataField} element describing the default target field.
*/
protected DataField getDataField(){
MiningFunction miningFunction = getMiningFunction();
switch(miningFunction){
case REGRESSION:
MathContext mathContext = getMathContext();
switch(mathContext){
case FLOAT:
return ModelEvaluator.DEFAULT_TARGET_CONTINUOUS_FLOAT;
default:
return ModelEvaluator.DEFAULT_TARGET_CONTINUOUS_DOUBLE;
}
case CLASSIFICATION:
case CLUSTERING:
return ModelEvaluator.DEFAULT_TARGET_CATEGORICAL_STRING;
default:
return null;
}
}
示例10: prepareTargetValue
import org.dmg.pmml.DataField; //导入依赖的package包/类
static
public FieldValue prepareTargetValue(DataField dataField, MiningField miningField, Target target, Object value){
DataType dataType = dataField.getDataType();
OpType opType = dataField.getOpType();
if(dataType == null || opType == null){
throw new InvalidElementException(dataField);
} // End if
if(miningField != null){
String invalidValueReplacement = miningField.getInvalidValueReplacement();
if(invalidValueReplacement != null){
throw new MisplacedAttributeException(miningField, PMMLAttributes.MININGFIELD_INVALIDVALUEREPLACEMENT, invalidValueReplacement);
}
String missingValueReplacement = miningField.getMissingValueReplacement();
if(missingValueReplacement != null){
throw new MisplacedAttributeException(miningField, PMMLAttributes.MININGFIELD_MISSINGVALUEREPLACEMENT, missingValueReplacement);
}
}
return createTargetValue(dataField, miningField, target, value);
}
示例11: getDataField
import org.dmg.pmml.DataField; //导入依赖的package包/类
@Override
protected DataField getDataField(){
MiningModel miningModel = getModel();
Segmentation segmentation = miningModel.getSegmentation();
Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
switch(multipleModelMethod){
case SELECT_ALL:
case SELECT_FIRST:
case MODEL_CHAIN:
return null;
default:
return super.getDataField();
}
}
示例12: SegmentHandler
import org.dmg.pmml.DataField; //导入依赖的package包/类
private SegmentHandler(ModelEvaluator<?> modelEvaluator){
setModelEvaluator(modelEvaluator);
boolean compatible = true;
List<InputField> inputFields = modelEvaluator.getInputFields();
for(InputField inputField : inputFields){
Field field = inputField.getField();
if(field instanceof DataField){
MiningField miningField = inputField.getMiningField();
compatible &= MiningFieldUtil.isDefault(miningField);
}
}
setCompatible(compatible);
}
示例13: getParameterSpecs
import org.dmg.pmml.DataField; //导入依赖的package包/类
public Map<String, String> getParameterSpecs() {
if(this.evaluator == null) {
return null;
}
Map<String, String> result = new HashMap<String, String>();
List<FieldName> activeFields = evaluator.getActiveFields();
for(FieldName activeField : activeFields) {
DataField dataField = evaluator.getDataField(activeField);
result.put(dataField.getName().getValue(), dataField.getDataType().name());
}
return result;
}
示例14: encodeInputFields
import org.dmg.pmml.DataField; //导入依赖的package包/类
static
private List<Field> encodeInputFields(List<InputField> inputFields){
Function<InputField, Field> function = new Function<InputField, Field>(){
@Override
public Field apply(InputField inputField){
FieldName name = inputField.getName();
DataField dataField = (DataField)inputField.getField();
Field field = new Field(name.getValue());
field.setName(dataField.getDisplayName());
field.setDataType(inputField.getDataType());
field.setOpType(inputField.getOpType());
field.setValues(encodeValues(dataField));
return field;
}
};
List<Field> fields = new ArrayList<>(Lists.transform(inputFields, function));
return fields;
}
示例15: encodeLabel
import org.dmg.pmml.DataField; //导入依赖的package包/类
@Override
public Label encodeLabel(FieldName targetField, List<String> targetCategories, PMMLEncoder encoder){
targetCategories = prepareTargetCategories(targetCategories);
DataField dataField = encoder.createDataField(targetField, OpType.CATEGORICAL, DataType.STRING, targetCategories);
return new CategoricalLabel(dataField);
}