本文整理汇总了Java中org.dmg.pmml.FieldName.create方法的典型用法代码示例。如果您正苦于以下问题:Java FieldName.create方法的具体用法?Java FieldName.create怎么用?Java FieldName.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dmg.pmml.FieldName
的用法示例。
在下文中一共展示了FieldName.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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);
}
示例3: buildMiningSchema
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
/**
* @param schema {@link InputSchema} whose information should be encoded in PMML
* @param importances optional feature importances. May be {@code null}, or else the size
* of the array must match the number of predictors in the schema, which may be
* less than the total number of features.
* @return a {@link MiningSchema} representing the information contained in an
* {@link InputSchema}
*/
public static MiningSchema buildMiningSchema(InputSchema schema, double[] importances) {
Preconditions.checkArgument(
importances == null || (importances.length == schema.getNumPredictors()));
List<String> featureNames = schema.getFeatureNames();
List<MiningField> miningFields = new ArrayList<>();
for (int featureIndex = 0; featureIndex < featureNames.size(); featureIndex++) {
String featureName = featureNames.get(featureIndex);
MiningField field = new MiningField(FieldName.create(featureName));
if (schema.isNumeric(featureName)) {
field.setOpType(OpType.CONTINUOUS);
field.setUsageType(MiningField.UsageType.ACTIVE);
} else if (schema.isCategorical(featureName)) {
field.setOpType(OpType.CATEGORICAL);
field.setUsageType(MiningField.UsageType.ACTIVE);
} else {
// ID, or ignored
field.setUsageType(MiningField.UsageType.SUPPLEMENTARY);
}
if (schema.hasTarget() && schema.isTarget(featureName)) {
// Override to PREDICTED
field.setUsageType(MiningField.UsageType.PREDICTED);
}
// Will be active if and only if it's a predictor
if (field.getUsageType() == MiningField.UsageType.ACTIVE && importances != null) {
int predictorIndex = schema.featureToPredictorIndex(featureIndex);
field.setImportance(importances[predictorIndex]);
}
miningFields.add(field);
}
return new MiningSchema(miningFields);
}
示例4: buildDataDictionary
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
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)) {
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());
}
示例5: pmmlClusteringModel
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
private ClusteringModel pmmlClusteringModel(KMeansModel model,
Map<Integer,Long> clusterSizesMap) {
Vector[] clusterCenters = model.clusterCenters();
List<ClusteringField> clusteringFields = new ArrayList<>();
for (int i = 0; i < inputSchema.getNumFeatures(); i++) {
if (inputSchema.isActive(i)) {
FieldName fieldName = FieldName.create(inputSchema.getFeatureNames().get(i));
ClusteringField clusteringField =
new ClusteringField(fieldName).setCenterField(ClusteringField.CenterField.TRUE);
clusteringFields.add(clusteringField);
}
}
List<Cluster> clusters = new ArrayList<>(clusterCenters.length);
for (int i = 0; i < clusterCenters.length; i++) {
clusters.add(new Cluster().setId(Integer.toString(i))
.setSize(clusterSizesMap.get(i).intValue())
.setArray(AppPMMLUtils.toArray(clusterCenters[i].toArray())));
}
return new ClusteringModel(
MiningFunction.CLUSTERING,
ClusteringModel.ModelClass.CENTER_BASED,
clusters.size(),
AppPMMLUtils.buildMiningSchema(inputSchema),
new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE).setMeasure(new SquaredEuclidean()),
clusteringFields,
clusters);
}
示例6: buildPredicate
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
private Predicate buildPredicate(Split split,
CategoricalValueEncodings categoricalValueEncodings) {
if (split == null) {
// Left child always applies, but is evaluated second
return new True();
}
int featureIndex = inputSchema.predictorToFeatureIndex(split.feature());
FieldName fieldName = FieldName.create(inputSchema.getFeatureNames().get(featureIndex));
if (split.featureType().equals(FeatureType.Categorical())) {
// Note that categories in MLlib model select the *left* child but the
// convention here will be that the predicate selects the *right* child
// So the predicate will evaluate "not in" this set
// More ugly casting
@SuppressWarnings("unchecked")
List<Double> javaCategories = (List<Double>) (List<?>)
JavaConversions.seqAsJavaList(split.categories());
Set<Integer> negativeEncodings = javaCategories.stream().map(Double::intValue).collect(Collectors.toSet());
Map<Integer,String> encodingToValue =
categoricalValueEncodings.getEncodingValueMap(featureIndex);
List<String> negativeValues = negativeEncodings.stream().map(encodingToValue::get).collect(Collectors.toList());
String joinedValues = TextUtils.joinPMMLDelimited(negativeValues);
return new SimpleSetPredicate(fieldName,
SimpleSetPredicate.BooleanOperator.IS_NOT_IN,
new Array(Array.Type.STRING, joinedValues));
} else {
// For MLlib, left means <= threshold, so right means >
return new SimplePredicate(fieldName, SimplePredicate.Operator.GREATER_THAN)
.setValue(Double.toString(split.threshold()));
}
}
示例7: TermFeature
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
public TermFeature(PMMLEncoder encoder, DefineFunction defineFunction, Feature feature, String value){
super(encoder, FieldName.create(defineFunction.getName() + "(" + value + ")"), defineFunction.getDataType());
setDefineFunction(defineFunction);
setFeature(feature);
setValue(value);
}
示例8: createFields
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
static
private FieldName[] createFields(String prefix, int count){
FieldName[] result = new FieldName[count];
for(int i = 0; i < count; i++){
result[i] = FieldName.create(prefix + "(" + (i + 1) + ")");
}
return result;
}
示例9: compactNegationExpression
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
@Test
public void compactNegationExpression(){
FieldRef fieldRef = new FieldRef(FieldName.create("x"));
Constant constant = createConstant("0");
Apply apply = compact(createApply("not", createApply("equal", fieldRef, constant)));
assertEquals("notEqual", apply.getFunction());
assertEquals(Arrays.asList(fieldRef, constant), apply.getExpressions());
apply = compact(createApply("not", createApply("isMissing", fieldRef)));
assertEquals("isNotMissing", apply.getFunction());
assertEquals(Arrays.asList(fieldRef), apply.getExpressions());
}
示例10: toContinuousFeature
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
@Override
public ContinuousOutputFeature toContinuousFeature(DataType dataType){
ContinuousOutputFeature continuousFeature = toContinuousFeature();
if((dataType).equals(continuousFeature.getDataType())){
return continuousFeature;
}
PMMLEncoder encoder = ensureEncoder();
FieldName name = FieldName.create((dataType.name()).toLowerCase() + "(" + (continuousFeature.getName()).getValue() + ")");
Output output = getOutput();
OutputField outputField = OutputUtil.getOutputField(output, name);
if(outputField == null){
outputField = new OutputField(name, dataType)
.setOpType(OpType.CONTINUOUS)
.setResultFeature(ResultFeature.TRANSFORMED_VALUE)
.setFinalResult(false)
.setExpression(continuousFeature.ref());
output.addOutputFields(outputField);
}
return new ContinuousOutputFeature(encoder, output, outputField.getName(), outputField.getDataType());
}
示例11: ensureDataField
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
public DataField ensureDataField(SavedModel savedModel, NodeDef placeholder){
if(!("Placeholder").equals(placeholder.getOp())){
throw new IllegalArgumentException(placeholder.getName());
}
FieldName name = FieldName.create(placeholder.getName());
DataField dataField = getDataField(name);
if(dataField == null){
Operation operation = savedModel.getOperation(placeholder.getName());
Output output = operation.output(0);
dataField = createDataField(name, TypeUtil.getOpType(output), TypeUtil.getDataType(output));
}
return dataField;
}
示例12: buildDummyClassificationModel
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
private static PMML buildDummyClassificationModel(int numTrees) {
PMML pmml = PMMLUtils.buildSkeletonPMML();
List<DataField> dataFields = new ArrayList<>();
DataField predictor =
new DataField(FieldName.create("color"), OpType.CATEGORICAL, DataType.STRING);
predictor.addValues(new Value("yellow"), new Value("red"));
dataFields.add(predictor);
DataField target =
new DataField(FieldName.create("fruit"), OpType.CATEGORICAL, DataType.STRING);
target.addValues(new Value("banana"), new Value("apple"));
dataFields.add(target);
DataDictionary dataDictionary =
new DataDictionary(dataFields).setNumberOfFields(dataFields.size());
pmml.setDataDictionary(dataDictionary);
List<MiningField> miningFields = new ArrayList<>();
MiningField predictorMF = new MiningField(FieldName.create("color"))
.setOpType(OpType.CATEGORICAL)
.setUsageType(MiningField.UsageType.ACTIVE)
.setImportance(0.5);
miningFields.add(predictorMF);
MiningField targetMF = new MiningField(FieldName.create("fruit"))
.setOpType(OpType.CATEGORICAL)
.setUsageType(MiningField.UsageType.PREDICTED);
miningFields.add(targetMF);
MiningSchema miningSchema = new MiningSchema(miningFields);
double dummyCount = 2.0;
Node rootNode = new Node().setId("r").setRecordCount(dummyCount).setPredicate(new True());
double halfCount = dummyCount / 2;
Node left = new Node().setId("r-").setRecordCount(halfCount).setPredicate(new True());
left.addScoreDistributions(new ScoreDistribution("apple", halfCount));
Node right = new Node().setId("r+").setRecordCount(halfCount)
.setPredicate(new SimpleSetPredicate(FieldName.create("color"),
SimpleSetPredicate.BooleanOperator.IS_NOT_IN,
new Array(Array.Type.STRING, "red")));
right.addScoreDistributions(new ScoreDistribution("banana", halfCount));
rootNode.addNodes(right, left);
TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, miningSchema, rootNode)
.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
.setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD);
if (numTrees > 1) {
MiningModel miningModel = new MiningModel(MiningFunction.CLASSIFICATION, miningSchema);
List<Segment> segments = new ArrayList<>();
for (int i = 0; i < numTrees; i++) {
segments.add(new Segment()
.setId(Integer.toString(i))
.setPredicate(new True())
.setModel(treeModel)
.setWeight(1.0));
}
miningModel.setSegmentation(
new Segmentation(Segmentation.MultipleModelMethod.WEIGHTED_MAJORITY_VOTE, segments));
pmml.addModels(miningModel);
} else {
pmml.addModels(treeModel);
}
return pmml;
}
示例13: encodeFeatures
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder){
CountVectorizerModel transformer = getTransformer();
DocumentFeature documentFeature = (DocumentFeature)encoder.getOnlyFeature(transformer.getInputCol());
ParameterField documentField = new ParameterField(FieldName.create("document"));
ParameterField termField = new ParameterField(FieldName.create("term"));
TextIndex textIndex = new TextIndex(documentField.getName())
.setTokenize(Boolean.TRUE)
.setWordSeparatorCharacterRE(documentFeature.getWordSeparatorRE())
.setLocalTermWeights(transformer.getBinary() ? TextIndex.LocalTermWeights.BINARY : null)
.setExpression(new FieldRef(termField.getName()));
Set<DocumentFeature.StopWordSet> stopWordSets = documentFeature.getStopWordSets();
for(DocumentFeature.StopWordSet stopWordSet : stopWordSets){
if(stopWordSet.isEmpty()){
continue;
}
DocumentBuilder documentBuilder = DOMUtil.createDocumentBuilder();
String tokenRE;
String wordSeparatorRE = documentFeature.getWordSeparatorRE();
switch(wordSeparatorRE){
case "\\s+":
tokenRE = "(^|\\s+)\\p{Punct}*(" + JOINER.join(stopWordSet) + ")\\p{Punct}*(\\s+|$)";
break;
case "\\W+":
tokenRE = "(\\W+)(" + JOINER.join(stopWordSet) + ")(\\W+)";
break;
default:
throw new IllegalArgumentException("Expected \"\\s+\" or \"\\W+\" as splitter regex pattern, got \"" + wordSeparatorRE + "\"");
}
InlineTable inlineTable = new InlineTable()
.addRows(DOMUtil.createRow(documentBuilder, Arrays.asList("string", "stem", "regex"), Arrays.asList(tokenRE, " ", "true")));
TextIndexNormalization textIndexNormalization = new TextIndexNormalization()
.setCaseSensitive(stopWordSet.isCaseSensitive())
.setRecursive(Boolean.TRUE) // Handles consecutive matches. See http://stackoverflow.com/a/25085385
.setInlineTable(inlineTable);
textIndex.addTextIndexNormalizations(textIndexNormalization);
}
DefineFunction defineFunction = new DefineFunction("tf" + "@" + String.valueOf(CountVectorizerModelConverter.SEQUENCE.getAndIncrement()), OpType.CONTINUOUS, null)
.setDataType(DataType.INTEGER)
.addParameterFields(documentField, termField)
.setExpression(textIndex);
encoder.addDefineFunction(defineFunction);
List<Feature> result = new ArrayList<>();
String[] vocabulary = transformer.vocabulary();
for(int i = 0; i < vocabulary.length; i++){
String term = vocabulary[i];
if(TermUtil.hasPunctuation(term)){
throw new IllegalArgumentException(term);
}
result.add(new TermFeature(encoder, defineFunction, documentFeature, term));
}
return result;
}
示例14: formatName
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
static
public <T extends Transformer & HasOutputCol> FieldName formatName(T transformer){
return FieldName.create(transformer.getOutputCol());
}
示例15: toWeightedTermFeature
import org.dmg.pmml.FieldName; //导入方法依赖的package包/类
public WeightedTermFeature toWeightedTermFeature(double weight){
PMMLEncoder encoder = ensureEncoder();
DefineFunction defineFunction = getDefineFunction();
String name = (defineFunction.getName()).replace("[email protected]", "[email protected]");
DefineFunction weightedDefineFunction = encoder.getDefineFunction(name);
if(weightedDefineFunction == null){
ParameterField weightField = new ParameterField(FieldName.create("weight"));
List<ParameterField> parameterFields = new ArrayList<>(defineFunction.getParameterFields());
parameterFields.add(weightField);
Apply apply = PMMLUtil.createApply("*", defineFunction.getExpression(), new FieldRef(weightField.getName()));
weightedDefineFunction = new DefineFunction(name, OpType.CONTINUOUS, parameterFields)
.setDataType(DataType.DOUBLE)
.setExpression(apply);
encoder.addDefineFunction(weightedDefineFunction);
}
return new WeightedTermFeature(encoder, weightedDefineFunction, getFeature(), getValue(), weight);
}