本文整理汇总了Java中org.dmg.pmml.SimpleSetPredicate类的典型用法代码示例。如果您正苦于以下问题:Java SimpleSetPredicate类的具体用法?Java SimpleSetPredicate怎么用?Java SimpleSetPredicate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleSetPredicate类属于org.dmg.pmml包,在下文中一共展示了SimpleSetPredicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluateSimpleSetPredicate
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
static
public Boolean evaluateSimpleSetPredicate(SimpleSetPredicate simpleSetPredicate, EvaluationContext context){
FieldName name = simpleSetPredicate.getField();
if(name == null){
throw new MissingAttributeException(simpleSetPredicate, PMMLAttributes.SIMPLESETPREDICATE_FIELD);
}
SimpleSetPredicate.BooleanOperator booleanOperator = simpleSetPredicate.getBooleanOperator();
if(booleanOperator == null){
throw new MissingAttributeException(simpleSetPredicate, PMMLAttributes.SIMPLESETPREDICATE_BOOLEANOPERATOR);
}
FieldValue value = context.evaluate(name);
if(value == null){
return null;
}
switch(booleanOperator){
case IS_IN:
return value.isIn(simpleSetPredicate);
case IS_NOT_IN:
return !value.isIn(simpleSetPredicate);
default:
throw new UnsupportedAttributeException(simpleSetPredicate, booleanOperator);
}
}
示例2: transform
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
private Predicate transform(SimpleSetPredicate simpleSetPredicate){
Array array = simpleSetPredicate.getArray();
List<String> content = ArrayUtil.getContent(array);
if(content.size() != 1){
return simpleSetPredicate;
}
String value = content.get(0);
SimpleSetPredicate.BooleanOperator booleanOperator = simpleSetPredicate.getBooleanOperator();
switch(booleanOperator){
case IS_IN:
return createSimplePredicate(simpleSetPredicate.getField(), SimplePredicate.Operator.EQUAL, value);
case IS_NOT_IN:
return createSimplePredicate(simpleSetPredicate.getField(), SimplePredicate.Operator.NOT_EQUAL, value);
default:
break;
}
return simpleSetPredicate;
}
示例3: intern
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
public Predicate intern(Predicate predicate){
if(predicate instanceof SimplePredicate){
return intern((SimplePredicate)predicate);
} else
if(predicate instanceof SimpleSetPredicate){
return intern((SimpleSetPredicate)predicate);
} else
if(predicate instanceof True){
return intern((True)predicate);
} else
if(predicate instanceof False){
return intern((False)predicate);
}
return predicate;
}
示例4: buildPredicate
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的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()));
}
}
示例5: getFieldNamesFromPredicate
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
protected static void getFieldNamesFromPredicate(Set<String> fieldNames, Predicate predicate) {
if (predicate instanceof CompoundPredicate) {
List<Predicate> predicates = ((CompoundPredicate) predicate).getPredicates();
for (Predicate predicate1 : predicates) {
getFieldNamesFromPredicate(fieldNames, predicate1);
}
} else {
if (predicate instanceof SimplePredicate) {
fieldNames.add(((SimplePredicate) predicate).getField().getValue());
} else if (predicate instanceof SimpleSetPredicate) {
fieldNames.add(((SimpleSetPredicate) predicate).getField().getValue());
}
}
}
示例6: createSimpleSetPredicate
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
public Predicate createSimpleSetPredicate(Feature feature, List<String> values){
if(values.size() == 1){
String value = values.get(0);
return createSimplePredicate(feature, SimplePredicate.Operator.EQUAL, value);
}
Predicate predicate = new InternableSimpleSetPredicate()
.setField(feature.getName())
.setBooleanOperator(SimpleSetPredicate.BooleanOperator.IS_IN)
.setArray(createArray(feature.getDataType(), values));
return intern(predicate);
}
示例7: evaluatePredicate
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
static
Boolean evaluatePredicate(Predicate predicate, EvaluationContext context){
if(predicate instanceof SimplePredicate){
return evaluateSimplePredicate((SimplePredicate)predicate, context);
} else
if(predicate instanceof SimpleSetPredicate){
return evaluateSimpleSetPredicate((SimpleSetPredicate)predicate, context);
} else
if(predicate instanceof CompoundPredicate){
return evaluateCompoundPredicate((CompoundPredicate)predicate, context);
} else
if(predicate instanceof True){
return evaluateTrue((True)predicate);
} else
if(predicate instanceof False){
return evaluateFalse((False)predicate);
} // End if
if(predicate instanceof JavaPredicate){
return evaluateJavaPredicate((JavaPredicate)predicate, context);
}
throw new UnsupportedElementException(predicate);
}
示例8: createKey
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
@Override
public ElementKey createKey(SimpleSetPredicate simpleSetPredicate){
Array array = simpleSetPredicate.getArray();
Object[] content = {simpleSetPredicate.getField(), simpleSetPredicate.getBooleanOperator(), ArrayUtil.getContent(array)};
return new ElementKey(content);
}
示例9: buildDummyClassificationModel
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的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;
}
示例10: visit
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
@Override
public VisitorAction visit(SimpleSetPredicate simpleSetPredicate){
process(simpleSetPredicate.getField());
return super.visit(simpleSetPredicate);
}
示例11: evaluateSimpleSetPredicate
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
@Test
public void evaluateSimpleSetPredicate(){
FieldName fruit = FieldName.create("fruit");
SimpleSetPredicate simpleSetPredicate = new SimpleSetPredicate(fruit, SimpleSetPredicate.BooleanOperator.IS_IN, new Array(Array.Type.STRING, "apple orange"));
assertEquals(null, evaluate(simpleSetPredicate, fruit, null));
assertEquals(Boolean.TRUE, evaluate(simpleSetPredicate, fruit, "apple"));
assertEquals(Boolean.FALSE, evaluate(simpleSetPredicate, fruit, "pineapple"));
simpleSetPredicate.setBooleanOperator(SimpleSetPredicate.BooleanOperator.IS_NOT_IN);
assertEquals(Boolean.FALSE, evaluate(simpleSetPredicate, fruit, "apple"));
assertEquals(Boolean.TRUE, evaluate(simpleSetPredicate, fruit, "pineapple"));
}
示例12: optimize
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
public Predicate optimize(Predicate predicate){
if(predicate instanceof SimplePredicate){
SimplePredicate simplePredicate = (SimplePredicate)predicate;
return new RichSimplePredicate(simplePredicate);
} else
if(predicate instanceof SimpleSetPredicate){
SimpleSetPredicate simpleSetPredicate = (SimpleSetPredicate)predicate;
return new RichSimpleSetPredicate(simpleSetPredicate);
}
return predicate;
}
示例13: RichSimpleSetPredicate
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
public RichSimpleSetPredicate(SimpleSetPredicate simpleSetPredicate){
ReflectionUtil.copyState(simpleSetPredicate, this);
}
示例14: optimizeSimpleSetPredicate
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
@Test
public void optimizeSimpleSetPredicate(){
Predicate predicate = new SimpleSetPredicate(FieldName.create("x"), SimpleSetPredicate.BooleanOperator.IS_IN, new Array(Array.Type.STRING, "1"));
checkTree(predicate, HasParsedValueSet.class);
}
示例15: addCategoricalField
import org.dmg.pmml.SimpleSetPredicate; //导入依赖的package包/类
private True addCategoricalField(SimpleSetPredicate simpleSetPredicate){
True truePredicate = new True();
this.categoricalFields.put(truePredicate, simpleSetPredicate.getField());
return truePredicate;
}