本文整理汇总了Java中org.dmg.pmml.FieldName类的典型用法代码示例。如果您正苦于以下问题:Java FieldName类的具体用法?Java FieldName怎么用?Java FieldName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FieldName类属于org.dmg.pmml包,在下文中一共展示了FieldName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeMiningModel
import org.dmg.pmml.FieldName; //导入依赖的package包/类
@Override
public MiningModel encodeMiningModel(List<Tree> trees, Integer numIteration, Schema schema){
Schema segmentSchema = new Schema(new ContinuousLabel(null, DataType.DOUBLE), schema.getFeatures());
List<MiningModel> miningModels = new ArrayList<>();
CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();
for(int i = 0, rows = categoricalLabel.size(), columns = (trees.size() / rows); i < rows; i++){
MiningModel miningModel = createMiningModel(FortranMatrixUtil.getRow(trees, rows, columns, i), numIteration, segmentSchema)
.setOutput(ModelUtil.createPredictedOutput(FieldName.create("lgbmValue(" + categoricalLabel.getValue(i) + ")"), OpType.CONTINUOUS, DataType.DOUBLE));
miningModels.add(miningModel);
}
return MiningModelUtil.createClassification(miningModels, RegressionModel.NormalizationMethod.SOFTMAX, true, schema);
}
示例2: testBuildCategoricalEncoding
import org.dmg.pmml.FieldName; //导入依赖的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());
}
示例3: registerOutputFields
import org.dmg.pmml.FieldName; //导入依赖的package包/类
@Override
public List<OutputField> registerOutputFields(Label label, SparkMLEncoder encoder){
T model = getTransformer();
String predictionCol = model.getPredictionCol();
OutputField predictedField = ModelUtil.createPredictedField(FieldName.create(predictionCol), DataType.STRING, OpType.CATEGORICAL);
Feature feature = new Feature(encoder, predictedField.getName(), predictedField.getDataType()){
@Override
public ContinuousFeature toContinuousFeature(){
throw new UnsupportedOperationException();
}
};
encoder.putOnlyFeature(predictionCol, feature);
return Collections.singletonList(predictedField);
}
示例4: encodeModel
import org.dmg.pmml.FieldName; //导入依赖的package包/类
@Override
public MiningModel encodeModel(Schema schema){
GBTClassificationModel model = getTransformer();
String lossType = model.getLossType();
switch(lossType){
case "logistic":
break;
default:
throw new IllegalArgumentException("Loss function " + lossType + " is not supported");
}
Schema segmentSchema = new Schema(new ContinuousLabel(null, DataType.DOUBLE), schema.getFeatures());
List<TreeModel> treeModels = TreeModelUtil.encodeDecisionTreeEnsemble(model, segmentSchema);
MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(segmentSchema.getLabel()))
.setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.WEIGHTED_SUM, treeModels, Doubles.asList(model.treeWeights())))
.setOutput(ModelUtil.createPredictedOutput(FieldName.create("gbtValue"), OpType.CONTINUOUS, DataType.DOUBLE));
return MiningModelUtil.createBinaryLogisticClassification(miningModel, 2d, 0d, RegressionModel.NormalizationMethod.LOGIT, false, schema);
}
示例5: encodeTreeModel
import org.dmg.pmml.FieldName; //导入依赖的package包/类
static
public TreeModel encodeTreeModel(org.apache.spark.ml.tree.Node node, PredicateManager predicateManager, MiningFunction miningFunction, Schema schema){
Node root = encodeNode(node, predicateManager, Collections.<FieldName, Set<String>>emptyMap(), miningFunction, schema)
.setPredicate(new True());
TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root)
.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);
String compact = TreeModelOptions.COMPACT;
if(compact != null && Boolean.valueOf(compact)){
Visitor visitor = new TreeModelCompactor();
visitor.applyTo(treeModel);
}
return treeModel;
}
示例6: createDataField
import org.dmg.pmml.FieldName; //导入依赖的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");
}
}
示例7: showEvaluatorDialog
import org.dmg.pmml.FieldName; //导入依赖的package包/类
private void showEvaluatorDialog(Evaluator evaluator){
List<FieldName> activeFields = getNames(evaluator.getActiveFields());
List<FieldName> targetFields = getNames(evaluator.getTargetFields());
List<FieldName> outputFields = getNames(evaluator.getOutputFields());
StringBuilder sb = new StringBuilder();
sb.append("Active fields: ").append(activeFields);
sb.append("\n");
sb.append("Target fields: ").append(targetFields);
sb.append("\n");
sb.append("Output fields: ").append(outputFields);
TextView textView = new TextView(this);
textView.setText(sb.toString());
Dialog dialog = new Dialog(this);
dialog.setContentView(textView);
dialog.show();
}
示例8: encodeMiningModel
import org.dmg.pmml.FieldName; //导入依赖的package包/类
@Override
public MiningModel encodeMiningModel(List<RegTree> regTrees, float base_score, Integer ntreeLimit, Schema schema){
Schema segmentSchema = new Schema(new ContinuousLabel(null, DataType.FLOAT), schema.getFeatures());
List<MiningModel> miningModels = new ArrayList<>();
CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();
for(int i = 0, columns = categoricalLabel.size(), rows = (regTrees.size() / columns); i < columns; i++){
MiningModel miningModel = createMiningModel(CMatrixUtil.getColumn(regTrees, rows, columns, i), base_score, ntreeLimit, segmentSchema)
.setOutput(ModelUtil.createPredictedOutput(FieldName.create("xgbValue(" + categoricalLabel.getValue(i) + ")"), OpType.CONTINUOUS, DataType.FLOAT));
miningModels.add(miningModel);
}
return MiningModelUtil.createClassification(miningModels, RegressionModel.NormalizationMethod.SOFTMAX, true, schema);
}
示例9: run
import org.dmg.pmml.FieldName; //导入依赖的package包/类
private void run() throws Exception {
Learner learner;
try(InputStream is = new FileInputStream(this.modelInput)){
learner = XGBoostUtil.loadLearner(is);
}
FeatureMap featureMap;
try(InputStream is = new FileInputStream(this.fmapInput)){
featureMap = XGBoostUtil.loadFeatureMap(is);
}
if(this.missingValue != null){
featureMap.addMissingValue(this.missingValue);
}
PMML pmml = learner.encodePMML(this.targetName != null ? FieldName.create(this.targetName) : null, this.targetCategories, featureMap, this.ntreeLimit, this.transform);
try(OutputStream os = new FileOutputStream(this.pmmlOutput)){
MetroJAXBUtil.marshalPMML(pmml, os);
}
}
示例10: createMiningSchema
import org.dmg.pmml.FieldName; //导入依赖的package包/类
static
public MiningSchema createMiningSchema(Label label){
MiningSchema miningSchema = new MiningSchema();
if(label != null){
FieldName name = label.getName();
if(name != null){
MiningField miningField = createMiningField(name, MiningField.UsageType.TARGET);
miningSchema.addMiningFields(miningField);
}
}
return miningSchema;
}
示例11: toContinuousFeature
import org.dmg.pmml.FieldName; //导入依赖的package包/类
public ContinuousFeature toContinuousFeature(DataType dataType){
ContinuousFeature continuousFeature = toContinuousFeature();
if((dataType).equals(continuousFeature.getDataType())){
return continuousFeature;
}
PMMLEncoder encoder = ensureEncoder();
FieldName name = FieldName.create((dataType.name()).toLowerCase() + "(" + (continuousFeature.getName()).getValue() + ")");
DerivedField derivedField = encoder.getDerivedField(name);
if(derivedField == null){
derivedField = encoder.createDerivedField(name, OpType.CONTINUOUS, dataType, continuousFeature.ref());
}
return new ContinuousFeature(encoder, derivedField);
}
示例12: translateArithmeticExpressionChain
import org.dmg.pmml.FieldName; //导入依赖的package包/类
@Test
public void translateArithmeticExpressionChain(){
Apply apply = (Apply)ExpressionTranslator.translateExpression("A + B - X + C");
List<Expression> expressions = checkApply(apply, "+", Apply.class, FieldRef.class);
Expression left = expressions.get(0);
Expression right = expressions.get(1);
expressions = checkApply((Apply)left, "-", Apply.class, FieldRef.class);
checkFieldRef((FieldRef)right, FieldName.create("C"));
left = expressions.get(0);
right = expressions.get(1);
expressions = checkApply((Apply)left, "+", FieldRef.class, FieldRef.class);
checkFieldRef((FieldRef)right, FieldName.create("X"));
left = expressions.get(0);
right = expressions.get(1);
checkFieldRef((FieldRef)left, FieldName.create("A"));
checkFieldRef((FieldRef)right, FieldName.create("B"));
}
示例13: toContinuous
import org.dmg.pmml.FieldName; //导入依赖的package包/类
public TypeDefinitionField toContinuous(FieldName name){
TypeDefinitionField field = getField(name);
DataType dataType = field.getDataType();
switch(dataType){
case INTEGER:
case FLOAT:
case DOUBLE:
break;
default:
throw new IllegalArgumentException("Field " + name.getValue() + " has data type " + dataType);
}
field.setOpType(OpType.CONTINUOUS);
return field;
}
示例14: resolveFeature
import org.dmg.pmml.FieldName; //导入依赖的package包/类
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);
}
}
示例15: wildcardFeature
import org.dmg.pmml.FieldName; //导入依赖的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));
}