类org.dmg.pmml.FieldName源码实例Demo

下面列出了怎么用org.dmg.pmml.FieldName的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jpmml-r   文件: AdaConverter.java
@Override
public Model encodeModel(Schema schema){
	RGenericVector ada = getObject();

	RGenericVector model = ada.getGenericElement("model");

	RGenericVector trees = model.getGenericElement("trees");
	RDoubleVector alpha = model.getDoubleElement("alpha");

	List<TreeModel> treeModels = encodeTreeModels(trees);

	MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(null))
		.setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.WEIGHTED_SUM, treeModels, alpha.getValues()))
		.setOutput(ModelUtil.createPredictedOutput(FieldName.create("adaValue"), OpType.CONTINUOUS, DataType.DOUBLE));

	return MiningModelUtil.createBinaryLogisticClassification(miningModel, 2d, 0d, RegressionModel.NormalizationMethod.LOGIT, true, schema);
}
 
源代码2 项目: jpmml-evaluator   文件: ExpressionUtilTest.java
@Test
public void evaluateApplyJavaFunction(){
	FieldName name = FieldName.create("x");

	FieldRef fieldRef = new FieldRef(name);

	Apply apply = new Apply(EchoFunction.class.getName())
		.addExpressions(fieldRef);

	try {
		evaluate(apply);

		fail();
	} catch(EvaluationException ee){
		assertEquals(fieldRef, ee.getContext());
	}

	assertEquals("Hello World!", evaluate(apply, name, "Hello World!"));
}
 
源代码3 项目: jpmml-sklearn   文件: MultiLookupTransformer.java
@Override
protected List<String> formatColumns(List<Feature> features){
	List<String> result = new ArrayList<>();

	for(Feature feature : features){
		FieldName name = feature.getName();

		result.add("data:" + XMLUtil.createTagName(name.getValue()));
	}

	if(result.contains("data:output")){
		throw new IllegalArgumentException();
	}

	result.add("data:output");

	return result;
}
 
源代码4 项目: jpmml-r   文件: FormulaUtil.java
static
private MapValues createMapValues(FieldName name, Map<String, String> mapping, List<String> categories){
	Set<String> inputs = new LinkedHashSet<>(mapping.keySet());
	Set<String> outputs = new LinkedHashSet<>(mapping.values());

	for(String category : categories){

		// Assume disjoint input and output value spaces
		if(outputs.contains(category)){
			continue;
		}

		mapping.put(category, category);
	}

	return PMMLUtil.createMapValues(name, mapping);
}
 
源代码5 项目: jpmml-lightgbm   文件: Classification.java
@Override
public Label encodeLabel(FieldName targetField, List<?> targetCategories, PMMLEncoder encoder){
	DataField dataField;

	if(targetCategories == null){
		targetCategories = LabelUtil.createTargetCategories(this.num_class_);

		dataField = encoder.createDataField(targetField, OpType.CATEGORICAL, DataType.INTEGER, targetCategories);
	} else

	{
		if(targetCategories.size() != this.num_class_){
			throw new IllegalArgumentException("Expected " + this.num_class_ + " target categories, got " + targetCategories.size() + " target categories");
		}

		dataField = encoder.createDataField(targetField, OpType.CATEGORICAL, DataType.STRING, targetCategories);
	}

	return new CategoricalLabel(dataField);
}
 
@Override
public FieldValue prepare(FieldName name, Object value){
	ParameterField parameterField = findParameterField(name);
	if(parameterField == null){
		throw new MissingFieldException(name);
	}

	DataType dataType = parameterField.getDataType();
	if(dataType == null){
		throw new MissingAttributeException(parameterField, PMMLAttributes.PARAMETERFIELD_DATATYPE);
	}

	OpType opType = parameterField.getOpType();
	if(opType == null){
		throw new MissingAttributeException(parameterField, PMMLAttributes.PARAMETERFIELD_OPTYPE);
	}

	return FieldValueUtil.create(dataType, opType, value);
}
 
源代码7 项目: jpmml-evaluator   文件: AssociationSchemaTest.java
private void evaluate(List<String> items, List<String> recommendations, List<String> exclusiveRecommendations, List<String> ruleAssociations) throws Exception {
	Evaluator evaluator = createModelEvaluator();

	checkTargetFields(Collections.emptyList(), evaluator);

	Map<FieldName, ?> arguments = createItemArguments(items);

	Map<FieldName, ?> results = evaluator.evaluate(arguments);

	assertEquals(recommendations, getOutput(results, "Recommendation"));
	assertEquals(exclusiveRecommendations, getOutput(results, "Exclusive_Recommendation"));
	assertEquals(ruleAssociations, getOutput(results, "Rule_Association"));

	assertEquals(Iterables.getFirst(recommendations, null), getOutput(results, "Top Recommendation"));
	assertEquals(Iterables.getFirst(exclusiveRecommendations, null), getOutput(results, "Top Exclusive_Recommendation"));
	assertEquals(Iterables.getFirst(ruleAssociations, null), getOutput(results, "Top Rule_Association"));
}
 
private Function<Integer, String> createIdentifierResolver(FieldName name, Table<Integer, FieldName, FieldValue> table){
	Function<Integer, String> function = new Function<Integer, String>(){

		@Override
		public String apply(Integer row){
			FieldValue value = table.get(row, name);
			if(FieldValueUtil.isMissing(value)){
				throw new MissingValueException(name);
			}

			return value.asString();
		}
	};

	return function;
}
 
源代码9 项目: jpmml-sparkml   文件: LinearSVCModelConverter.java
@Override
public MiningModel encodeModel(Schema schema){
	LinearSVCModel model = getTransformer();

	Transformation transformation = new AbstractTransformation(){

		@Override
		public Expression createExpression(FieldRef fieldRef){
			return PMMLUtil.createApply(PMMLFunctions.THRESHOLD)
				.addExpressions(fieldRef, PMMLUtil.createConstant(model.getThreshold()));
		}
	};

	Schema segmentSchema = schema.toAnonymousRegressorSchema(DataType.DOUBLE);

	Model linearModel = LinearModelUtil.createRegression(this, model.coefficients(), model.intercept(), segmentSchema)
		.setOutput(ModelUtil.createPredictedOutput(FieldName.create("margin"), OpType.CONTINUOUS, DataType.DOUBLE, transformation));

	return MiningModelUtil.createBinaryLogisticClassification(linearModel, 1d, 0d, RegressionModel.NormalizationMethod.NONE, false, schema);
}
 
源代码10 项目: jpmml-evaluator   文件: MissingValueStrategyTest.java
@Test
public void defaultChildMultiplePenalties() throws Exception {
	Map<FieldName, ?> arguments = createArguments("outlook", null, "temperature", null, "humidity", 70d);

	NodeScoreDistribution<?> targetValue = evaluate(TreeModel.MissingValueStrategy.DEFAULT_CHILD, 0.8d, arguments);

	assertEquals("3", targetValue.getEntityId());

	assertEquals((Double)0.9d, targetValue.getProbability("will play"));
	assertEquals((Double)0.05d, targetValue.getProbability("may play"));
	assertEquals((Double)0.05d, targetValue.getProbability("no play"));

	double missingValuePenalty = (0.8d * 0.8d);

	assertEquals((Double)(0.9d * missingValuePenalty), targetValue.getConfidence("will play"));
	assertEquals((Double)(0.05d * missingValuePenalty), targetValue.getConfidence("may play"));
	assertEquals((Double)(0.05d * missingValuePenalty), targetValue.getConfidence("no play"));
}
 
源代码11 项目: jpmml-sparkml   文件: ExpressionTranslatorTest.java
@Test
public void translateArithmeticExpression(){
	String string = "-((x1 - 1) / (x2 + 1))";

	Apply expected = PMMLUtil.createApply(PMMLFunctions.MULTIPLY)
		.addExpressions(PMMLUtil.createConstant(-1))
		.addExpressions(PMMLUtil.createApply(PMMLFunctions.DIVIDE)
			.addExpressions(PMMLUtil.createApply(PMMLFunctions.SUBTRACT)
				.addExpressions(new FieldRef(FieldName.create("x1")), PMMLUtil.createConstant(1, DataType.DOUBLE))
			)
			.addExpressions(PMMLUtil.createApply(PMMLFunctions.ADD)
				.addExpressions(new FieldRef(FieldName.create("x2")), PMMLUtil.createConstant(1, DataType.DOUBLE))
			)
		);

	checkExpression(expected, string);
}
 
源代码12 项目: jpmml-evaluator   文件: PredicateUtilTest.java
static
private Boolean evaluate(Predicate predicate, Map<FieldName, ?> arguments){
	EvaluationContext context = new VirtualEvaluationContext();
	context.declareAll(arguments);

	return PredicateUtil.evaluate(predicate, context);
}
 
源代码13 项目: jpmml-r   文件: ExpressionTranslatorTest.java
@Test
public void translateLogicalExpressionChain(){
	String string = "(x == 0) | ((x == 1) | (x == 2)) | x == 3";

	Apply left = PMMLUtil.createApply(PMMLFunctions.EQUAL)
		.addExpressions(new FieldRef(FieldName.create("x")), PMMLUtil.createConstant("0", DataType.INTEGER));

	Apply middleLeft = PMMLUtil.createApply(PMMLFunctions.EQUAL)
		.addExpressions(new FieldRef(FieldName.create("x")), PMMLUtil.createConstant("1", DataType.INTEGER));

	Apply middleRight = PMMLUtil.createApply(PMMLFunctions.EQUAL)
		.addExpressions(new FieldRef(FieldName.create("x")), PMMLUtil.createConstant("2", DataType.INTEGER));

	Apply right = PMMLUtil.createApply(PMMLFunctions.EQUAL)
		.addExpressions(new FieldRef(FieldName.create("x")), PMMLUtil.createConstant("3", DataType.INTEGER));

	Expression expected = PMMLUtil.createApply(PMMLFunctions.OR)
		.addExpressions(PMMLUtil.createApply(PMMLFunctions.OR)
			.addExpressions(left)
			.addExpressions(PMMLUtil.createApply(PMMLFunctions.OR)
				.addExpressions(middleLeft, middleRight)
			)
		)
		.addExpressions(right);

	Expression actual = ExpressionTranslator.translateExpression(string, false);

	assertTrue(ReflectionUtil.equals(expected, actual));

	expected = PMMLUtil.createApply(PMMLFunctions.OR)
		.addExpressions(left, middleLeft, middleRight, right);

	actual = ExpressionTranslator.translateExpression(string, true);

	assertTrue(ReflectionUtil.equals(expected, actual));
}
 
private PredictorHandler(PPCell ppCell){
	setPPCell(ppCell);

	FieldName name = ppCell.getField();
	if(name == null){
		throw new MissingAttributeException(ppCell, PMMLAttributes.PPCELL_FIELD);
	}
}
 
源代码15 项目: jpmml-evaluator   文件: AttributeReasonCodeTest.java
@Test
public void evaluate() throws Exception {
	Map<FieldName, ?> result = evaluateExample();

	assertEquals(29d, getOutput(result, "Final Score"));

	assertEquals("RC2_3", getOutput(result, "Reason Code 1"));
	assertEquals("RC1", getOutput(result, "Reason Code 2"));
	assertEquals(null, getOutput(result, "Reason Code 3"));
}
 
源代码16 项目: oryx   文件: RDFUpdate.java
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")
    Collection<Double> javaCategories = (Collection<Double>) (Collection<?>)
        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,
        Double.toString(split.threshold()));
  }
}
 
源代码17 项目: jpmml-evaluator   文件: ValueParser.java
@Override
public VisitorAction visit(SimplePredicate simplePredicate){
	FieldName name = simplePredicate.getField();
	if(name == null){
		throw new MissingAttributeException(simplePredicate, PMMLAttributes.SIMPLEPREDICATE_FIELD);
	} // End if

	if(simplePredicate.hasValue()){
		parseValue(name, simplePredicate);
	}

	return super.visit(simplePredicate);
}
 
源代码18 项目: konduit-serving   文件: RegressionOutputAdapter.java
@Override
public RegressionOutput adapt(Object input, RoutingContext routingContext) {
    if (input instanceof INDArray) {
        INDArray arr = (INDArray) input;
        return adapt(arr, routingContext);
    } else if (input instanceof List) {
        List<? extends Map<FieldName, ?>> pmmlExamples = (List<? extends Map<FieldName, ?>>) input;
        return adapt(pmmlExamples, routingContext);
    }

    throw new UnsupportedOperationException("Unable to convert input of type " + input);
}
 
源代码19 项目: jpmml-evaluator   文件: ModelEvaluator.java
static
private <F extends ModelField> List<F> updateNames(List<F> fields, java.util.function.Function<FieldName, FieldName> mapper){

	for(F field : fields){
		FieldName name = field.getFieldName();

		FieldName mappedName = mapper.apply(name);
		if(mappedName != null && !Objects.equals(mappedName, name)){
			field.setName(mappedName);
		}
	}

	return fields;
}
 
源代码20 项目: jpmml-evaluator   文件: ConfigurationBuilder.java
public Configuration build(){
	Configuration configuration = new Configuration();

	ModelEvaluatorFactory modelEvaluatorFactory = getModelEvaluatorFactory();
	if(modelEvaluatorFactory == null){
		modelEvaluatorFactory = ModelEvaluatorFactory.newInstance();
	}

	configuration.setModelEvaluatorFactory(modelEvaluatorFactory);

	ValueFactoryFactory valueFactoryFactory = getValueFactoryFactory();
	if(valueFactoryFactory == null){
		valueFactoryFactory = ValueFactoryFactory.newInstance();
	}

	configuration.setValueFactoryFactory(valueFactoryFactory);

	OutputFilter outputFilter = getOutputFilter();
	if(outputFilter == null){
		outputFilter = OutputFilters.KEEP_ALL;
	}

	configuration.setOutputFilter(outputFilter);

	SymbolTable<FieldName> derivedFieldGuard = getDerivedFieldGuard();
	SymbolTable<String> functionGuard = getFunctionGuard();

	configuration.setDerivedFieldGuard(derivedFieldGuard);
	configuration.setFunctionGuard(functionGuard);

	return configuration;
}
 
源代码21 项目: jpmml-evaluator   文件: ModelManager.java
protected ListMultimap<FieldName, Field<?>> getVisibleFields(){

		if(this.visibleFields == null){
			this.visibleFields = collectVisibleFields();
		}

		return this.visibleFields;
	}
 
源代码22 项目: jpmml-model   文件: FieldReferenceFinder.java
public Set<FieldName> getFieldNames(){

		if(this.names == null){
			return Collections.emptySet();
		}

		return Collections.unmodifiableSet(this.names);
	}
 
源代码23 项目: jpmml-evaluator   文件: ModelManager.java
public DataField getDataField(FieldName name){

		if(Objects.equals(Evaluator.DEFAULT_TARGET_NAME, name)){
			return getDefaultDataField();
		}

		return this.dataFields.get(name);
	}
 
源代码24 项目: jpmml-evaluator   文件: TreeModelEvaluator.java
@Override
protected <V extends Number> Map<FieldName, ?> evaluateRegression(ValueFactory<V> valueFactory, EvaluationContext context){
	TargetField targetField = getTargetField();

	Trail trail = new Trail();

	Node node = evaluateTree(trail, context);
	if(node == null){
		return TargetUtil.evaluateRegressionDefault(valueFactory, targetField);
	}

	NodeScore<V> result = createNodeScore(valueFactory, targetField, node);

	return TargetUtil.evaluateRegression(targetField, result);
}
 
源代码25 项目: jpmml-evaluator   文件: ExpressionUtilTest.java
@Test
public void evaluateTextIndexNormalization(){
	FieldName name = FieldName.create("x");

	TextIndexNormalization stepOne = new TextIndexNormalization();

	List<List<String>> cells = Arrays.asList(
		Arrays.asList("interfaces?", "interface", "true"),
		Arrays.asList("is|are|seem(ed|s?)|were", "be", "true"),
		Arrays.asList("user friendl(y|iness)", "user_friendly", "true")
	);

	stepOne.setInlineTable(createInlineTable(cells, stepOne));

	TextIndexNormalization stepTwo = new TextIndexNormalization()
		.setInField("re")
		.setOutField("feature");

	cells = Arrays.asList(
		Arrays.asList("interface be (user_friendly|well designed|excellent)", "ui_good", "true")
	);

	stepTwo.setInlineTable(createInlineTable(cells, stepTwo));

	TextIndex textIndex = new TextIndex(name, new Constant("ui_good"))
		.setLocalTermWeights(TextIndex.LocalTermWeights.BINARY)
		.setCaseSensitive(false)
		.addTextIndexNormalizations(stepOne, stepTwo);

	assertEquals(1, evaluate(textIndex, name, "Testing the app for a few days convinced me the interfaces are excellent!"));
}
 
源代码26 项目: jpmml-xgboost   文件: LogisticRegression.java
@Override
public MiningModel encodeMiningModel(List<RegTree> trees, List<Float> weights, float base_score, Integer ntreeLimit, Schema schema){
	Schema segmentSchema = schema.toAnonymousSchema();

	MiningModel miningModel = createMiningModel(trees, weights, base_score, ntreeLimit, segmentSchema)
		.setOutput(ModelUtil.createPredictedOutput(FieldName.create("xgbValue"), OpType.CONTINUOUS, DataType.FLOAT));

	return MiningModelUtil.createRegression(miningModel, RegressionModel.NormalizationMethod.LOGIT, schema);
}
 
源代码27 项目: jpmml-model   文件: FieldNameUtil.java
static
public Set<FieldName> create(Set<FieldName> parent, String... values){
	Set<FieldName> result = new LinkedHashSet<>(parent);

	for(String value : values){
		result.add(FieldName.create(value));
	}

	return result;
}
 
源代码28 项目: jpmml-sklearn   文件: PMMLPipeline.java
static
private List<Feature> initFeatures(List<String> activeFields, OpType opType, DataType dataType, SkLearnEncoder encoder){
	List<Feature> result = new ArrayList<>();

	for(String activeField : activeFields){
		DataField dataField = encoder.createDataField(FieldName.create(activeField), opType, dataType);

		result.add(new WildcardFeature(encoder, dataField));
	}

	return result;
}
 
@Override
public void addInput(@NonNull List<Map<FieldName, Object>> input) {
    synchronized (locker) {
        if (this.input == null)
            this.input = new ArrayList<>();
        this.input.addAll(input);
        position.set(counter.getAndIncrement());

        if (isReadLocked.get())
            realLocker.readLock().unlock();
    }
    this.input = input;
}
 
源代码30 项目: jpmml-r   文件: PreProcessEncoder.java
private Expression encodeExpression(FieldName name, Expression expression){
	List<Double> ranges = this.ranges.get(name);
	if(ranges != null){
		Double min = ranges.get(0);
		Double max = ranges.get(1);

		if(!ValueUtil.isZero(min)){
			expression = PMMLUtil.createApply(PMMLFunctions.SUBTRACT, expression, PMMLUtil.createConstant(min));
		} // End if

		if(!ValueUtil.isOne(max - min)){
			expression = PMMLUtil.createApply(PMMLFunctions.DIVIDE, expression, PMMLUtil.createConstant(max - min));
		}
	}

	Double mean = this.mean.get(name);
	if(mean != null && !ValueUtil.isZero(mean)){
		expression = PMMLUtil.createApply(PMMLFunctions.SUBTRACT, expression, PMMLUtil.createConstant(mean));
	}

	Double std = this.std.get(name);
	if(std != null && !ValueUtil.isOne(std)){
		expression = PMMLUtil.createApply(PMMLFunctions.DIVIDE, expression, PMMLUtil.createConstant(std));
	}

	Double median = this.median.get(name);
	if(median != null){
		expression = PMMLUtil.createApply(PMMLFunctions.IF)
			.addExpressions(PMMLUtil.createApply(PMMLFunctions.ISNOTMISSING, new FieldRef(name)))
			.addExpressions(expression, PMMLUtil.createConstant(median));
	}

	return expression;
}
 
 类所在包
 类方法
 同包方法