当前位置: 首页>>代码示例>>Java>>正文


Java PMMLUtil.createApply方法代码示例

本文整理汇总了Java中org.jpmml.converter.PMMLUtil.createApply方法的典型用法代码示例。如果您正苦于以下问题:Java PMMLUtil.createApply方法的具体用法?Java PMMLUtil.createApply怎么用?Java PMMLUtil.createApply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jpmml.converter.PMMLUtil的用法示例。


在下文中一共展示了PMMLUtil.createApply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encodeFeatures

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder){
	RegexTokenizer transformer = getTransformer();

	if(!transformer.getGaps()){
		throw new IllegalArgumentException("Expected splitter mode, got token matching mode");
	} // End if

	if(transformer.getMinTokenLength() != 1){
		throw new IllegalArgumentException("Expected 1 as minimum token length, got " + transformer.getMinTokenLength() + " as minimum token length");
	}

	Feature feature = encoder.getOnlyFeature(transformer.getInputCol());

	TypeDefinitionField field = encoder.getField(feature.getName());

	if(transformer.getToLowercase()){
		Apply apply = PMMLUtil.createApply("lowercase", feature.ref());

		field = encoder.createDerivedField(FeatureUtil.createName("lowercase", feature), OpType.CATEGORICAL, DataType.STRING, apply);
	}

	return Collections.<Feature>singletonList(new DocumentFeature(encoder, field, transformer.getPattern()));
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:25,代码来源:RegexTokenizerConverter.java

示例2: encodeDefineFunction

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
@Override
public DefineFunction encodeDefineFunction(){
	TfidfTransformer transformer = getTransformer();

	DefineFunction defineFunction = super.encodeDefineFunction();

	Expression expression = defineFunction.getExpression();

	Boolean sublinearTf = transformer.getSublinearTf();
	if(sublinearTf){
		expression = PMMLUtil.createApply("+", PMMLUtil.createApply("log", expression), PMMLUtil.createConstant(1d));
	} // End if

	Boolean useIdf = transformer.getUseIdf();
	if(useIdf){
		ParameterField weight = new ParameterField(FieldName.create("weight"));

		defineFunction.addParameterFields(weight);

		expression = PMMLUtil.createApply("*", expression, new FieldRef(weight.getName()));
	}

	defineFunction.setExpression(expression);

	return defineFunction;
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:27,代码来源:TfidfVectorizer.java

示例3: createHingeFunction

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
static
private Apply createHingeFunction(int dir, Feature feature, double cut){
	Expression expression;

	switch(dir){
		case -1:
			expression = PMMLUtil.createApply("-", PMMLUtil.createConstant(cut), feature.ref());
			break;
		case 1:
			expression = PMMLUtil.createApply("-", feature.ref(), PMMLUtil.createConstant(cut));
			break;
		default:
			throw new IllegalArgumentException();
	}

	return PMMLUtil.createApply("max", expression, PMMLUtil.createConstant(0d));
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:18,代码来源:EarthConverter.java

示例4: encodeFeatures

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder){
	PCAModel transformer = getTransformer();

	List<Feature> features = encoder.getFeatures(transformer.getInputCol());

	DenseMatrix pc = transformer.pc();
	if(pc.numRows() != features.size()){
		throw new IllegalArgumentException();
	}

	List<Feature> result = new ArrayList<>();

	for(int i = 0; i < transformer.getK(); i++){
		Apply apply = new Apply("sum");

		for(int j = 0; j < features.size(); j++){
			Feature feature = features.get(j);

			ContinuousFeature continuousFeature = feature.toContinuousFeature();

			Expression expression = continuousFeature.ref();

			Double coefficient = pc.apply(j, i);
			if(!ValueUtil.isOne(coefficient)){
				expression = PMMLUtil.createApply("*", expression, PMMLUtil.createConstant(coefficient));
			}

			apply.addExpressions(expression);
		}

		DerivedField derivedField = encoder.createDerivedField(formatName(transformer, i), OpType.CONTINUOUS, DataType.DOUBLE, apply);

		result.add(new ContinuousFeature(encoder, derivedField));
	}

	return result;
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:39,代码来源:PCAModelConverter.java

示例5: createApply

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
public Apply createApply(){
	DefineFunction defineFunction = getDefineFunction();
	Feature feature = getFeature();
	String value = getValue();

	Constant constant = PMMLUtil.createConstant(value)
		.setDataType(DataType.STRING);

	return PMMLUtil.createApply(defineFunction.getName(), feature.ref(), constant);
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:11,代码来源:TermFeature.java

示例6: encodeModel

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
@Override
public SupportVectorMachineModel encodeModel(Schema schema){
	Transformation outlier = new OutlierTransformation(){

		@Override
		public Expression createExpression(FieldRef fieldRef){
			return PMMLUtil.createApply("lessOrEqual", fieldRef, PMMLUtil.createConstant(0d));
		}
	};

	SupportVectorMachineModel supportVectorMachineModel = super.encodeModel(schema)
		.setOutput(ModelUtil.createPredictedOutput(FieldName.create("decisionFunction"), OpType.CONTINUOUS, DataType.DOUBLE, outlier));

	return supportVectorMachineModel;
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:16,代码来源:OneClassSVM.java

示例7: encodeExpression

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
private Expression encodeExpression(Feature feature){
	FieldName name = feature.getName();

	Expression expression = feature.ref();

	List<Double> ranges = this.ranges.get(name);
	if(ranges != null){
		Double min = ranges.get(0);
		Double max = ranges.get(1);

		expression = PMMLUtil.createApply("/", PMMLUtil.createApply("-", expression, PMMLUtil.createConstant(min)), PMMLUtil.createConstant(max - min));
	}

	Double mean = this.mean.get(name);
	if(mean != null){
		expression = PMMLUtil.createApply("-", expression, PMMLUtil.createConstant(mean));
	}

	Double std = this.std.get(name);
	if(std != null){
		expression = PMMLUtil.createApply("/", expression, PMMLUtil.createConstant(std));
	}

	Double median = this.median.get(name);
	if(median != null){
		expression = PMMLUtil.createApply("if", PMMLUtil.createApply("isNotMissing", new FieldRef(name)), expression, PMMLUtil.createConstant(median));
	} // End if

	if(expression instanceof FieldRef){
		return null;
	}

	return expression;
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:35,代码来源:PreProcessEncoder.java

示例8: encodeFeatures

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder){
	StringIndexerModel transformer = getTransformer();

	Feature feature = encoder.getOnlyFeature(transformer.getInputCol());

	List<String> categories = new ArrayList<>();
	categories.addAll(Arrays.asList(transformer.labels()));

	String handleInvalid = transformer.getHandleInvalid();

	TypeDefinitionField field = encoder.toCategorical(feature.getName(), categories);

	if(field instanceof DataField){
		DataField dataField = (DataField)field;

		InvalidValueTreatmentMethod invalidValueTreatmentMethod;

		switch(handleInvalid){
			case "keep":
				invalidValueTreatmentMethod = InvalidValueTreatmentMethod.AS_IS;
				break;
			case "error":
				invalidValueTreatmentMethod = InvalidValueTreatmentMethod.RETURN_INVALID;
				break;
			default:
				throw new IllegalArgumentException(handleInvalid);
		}

		InvalidValueDecorator invalidValueDecorator = new InvalidValueDecorator()
			.setInvalidValueTreatment(invalidValueTreatmentMethod);

		encoder.addDecorator(dataField.getName(), invalidValueDecorator);
	} else

	if(field instanceof DerivedField){
		// Ignored
	} else

	{
		throw new IllegalArgumentException();
	}

	switch(handleInvalid){
		case "keep":
			Apply setApply = PMMLUtil.createApply("isIn", feature.ref());

			for(String category : categories){
				setApply.addExpressions(PMMLUtil.createConstant(category));
			}

			categories.add(StringIndexerModelConverter.LABEL_UNKNOWN);

			Apply apply = PMMLUtil.createApply("if", setApply, feature.ref(), PMMLUtil.createConstant(StringIndexerModelConverter.LABEL_UNKNOWN));

			field = encoder.createDerivedField(FeatureUtil.createName("handleInvalid", feature), OpType.CATEGORICAL, feature.getDataType(), apply);
			break;
		default:
			break;
	}

	return Collections.<Feature>singletonList(new CategoricalFeature(encoder, field, categories));
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:64,代码来源:StringIndexerModelConverter.java

示例9: encodeFeatures

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder){
	StandardScalerModel transformer = getTransformer();

	List<Feature> features = encoder.getFeatures(transformer.getInputCol());

	Vector mean = transformer.mean();
	if(transformer.getWithMean() && mean.size() != features.size()){
		throw new IllegalArgumentException();
	}

	Vector std = transformer.std();
	if(transformer.getWithStd() && std.size() != features.size()){
		throw new IllegalArgumentException();
	}

	List<Feature> result = new ArrayList<>();

	for(int i = 0; i < features.size(); i++){
		Feature feature = features.get(i);

		ContinuousFeature continuousFeature = feature.toContinuousFeature();

		Expression expression = continuousFeature.ref();

		if(transformer.getWithMean()){
			double meanValue = mean.apply(i);

			if(!ValueUtil.isZero(meanValue)){
				expression = PMMLUtil.createApply("-", expression, PMMLUtil.createConstant(meanValue));
			}
		} // End if

		if(transformer.getWithStd()){
			double stdValue = std.apply(i);

			if(!ValueUtil.isOne(stdValue)){
				expression = PMMLUtil.createApply("*", expression, PMMLUtil.createConstant(1d / stdValue));
			}
		}

		DerivedField derivedField = encoder.createDerivedField(formatName(transformer, i), OpType.CONTINUOUS, DataType.DOUBLE, expression);

		result.add(new ContinuousFeature(encoder, derivedField));
	}

	return result;
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:49,代码来源:StandardScalerModelConverter.java

示例10: encodeFeatures

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder){
	MinMaxScalerModel transformer = getTransformer();

	double rescaleFactor = (transformer.getMax() - transformer.getMin());
	double rescaleConstant = transformer.getMin();

	List<Feature> features = encoder.getFeatures(transformer.getInputCol());

	Vector originalMax = transformer.originalMax();
	if(originalMax.size() != features.size()){
		throw new IllegalArgumentException();
	}

	Vector originalMin = transformer.originalMin();
	if(originalMin.size() != features.size()){
		throw new IllegalArgumentException();
	}

	List<Feature> result = new ArrayList<>();

	for(int i = 0; i < features.size(); i++){
		Feature feature = features.get(i);

		ContinuousFeature continuousFeature = feature.toContinuousFeature();

		double max = originalMax.apply(i);
		double min = originalMin.apply(i);

		Expression expression = PMMLUtil.createApply("/", PMMLUtil.createApply("-", continuousFeature.ref(), PMMLUtil.createConstant(min)), PMMLUtil.createConstant(max - min));

		if(!ValueUtil.isOne(rescaleFactor)){
			expression = PMMLUtil.createApply("*", expression, PMMLUtil.createConstant(rescaleFactor));
		} // End if

		if(!ValueUtil.isZero(rescaleConstant)){
			expression = PMMLUtil.createApply("+", expression, PMMLUtil.createConstant(rescaleConstant));
		}

		DerivedField derivedField = encoder.createDerivedField(formatName(transformer, i), OpType.CONTINUOUS, DataType.DOUBLE, expression);

		result.add(new ContinuousFeature(encoder, derivedField));
	}

	return result;
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:47,代码来源:MinMaxScalerModelConverter.java

示例11: toWeightedTermFeature

import org.jpmml.converter.PMMLUtil; //导入方法依赖的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);
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:26,代码来源:TermFeature.java

示例12: encodeApply

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
public Apply encodeApply(String function, Feature feature, int index, String term){
	Constant constant = PMMLUtil.createConstant(term)
		.setDataType(DataType.STRING);

	return PMMLUtil.createApply(function, feature.ref(), constant);
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:7,代码来源:CountVectorizer.java

示例13: encodeFeatures

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
@Override
public List<Feature> encodeFeatures(List<Feature> features, SkLearnEncoder encoder){
	Boolean withCentering = getWithCentering();
	Boolean withScaling = getWithScaling();

	List<? extends Number> center = (withCentering ? getCenter() : null);
	List<? extends Number> scale = (withScaling ? getScale() : null);

	if(center == null && scale == null){
		return features;
	}

	ClassDictUtil.checkSize(features, center, scale);

	List<Feature> result = new ArrayList<>();

	for(int i = 0; i < features.size(); i++){
		Feature feature = features.get(i);

		Number centerValue = (withCentering ? center.get(i) : 0d);
		Number scaleValue = (withScaling ? scale.get(i) : 1d);

		if(ValueUtil.isZero(centerValue) && ValueUtil.isOne(scaleValue)){
			result.add(feature);

			continue;
		}

		ContinuousFeature continuousFeature = feature.toContinuousFeature();

		// "($name - center) / scale"
		Expression expression = continuousFeature.ref();

		if(!ValueUtil.isZero(centerValue)){
			expression = PMMLUtil.createApply("-", expression, PMMLUtil.createConstant(centerValue));
		} // End if

		if(!ValueUtil.isOne(scaleValue)){
			expression = PMMLUtil.createApply("/", expression, PMMLUtil.createConstant(scaleValue));
		}

		DerivedField derivedField = encoder.createDerivedField(createName(continuousFeature), expression);

		result.add(new ContinuousFeature(encoder, derivedField));
	}

	return result;
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:49,代码来源:RobustScaler.java

示例14: encodeFeatures

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
@Override
public List<Feature> encodeFeatures(List<Feature> features, SkLearnEncoder encoder){
	List<? extends Number> min = getMin();
	List<? extends Number> scale = getScale();

	ClassDictUtil.checkSize(features, min, scale);

	List<Feature> result = new ArrayList<>();

	for(int i = 0; i < features.size(); i++){
		Feature feature = features.get(i);

		Number minValue = min.get(i);
		Number scaleValue = scale.get(i);

		if(ValueUtil.isOne(scaleValue) && ValueUtil.isZero(minValue)){
			result.add(feature);

			continue;
		}

		ContinuousFeature continuousFeature = feature.toContinuousFeature();

		// "($name * scale) + min"
		Expression expression = continuousFeature.ref();

		if(!ValueUtil.isOne(scaleValue)){
			expression = PMMLUtil.createApply("*", expression, PMMLUtil.createConstant(scaleValue));
		} // End if

		if(!ValueUtil.isZero(minValue)){
			expression = PMMLUtil.createApply("+", expression, PMMLUtil.createConstant(minValue));
		}

		DerivedField derivedField = encoder.createDerivedField(createName(continuousFeature), expression);

		result.add(new ContinuousFeature(encoder, derivedField));
	}

	return result;
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:42,代码来源:MinMaxScaler.java

示例15: encodeFeatures

import org.jpmml.converter.PMMLUtil; //导入方法依赖的package包/类
@Override
public List<Feature> encodeFeatures(List<Feature> features, SkLearnEncoder encoder){
	Boolean withMean = getWithMean();
	Boolean withStd = getWithStd();

	List<? extends Number> mean = (withMean ? getMean() : null);
	List<? extends Number> std = (withStd ? getStd() : null);

	if(mean == null && std == null){
		return features;
	}

	ClassDictUtil.checkSize(features, mean, std);

	List<Feature> result = new ArrayList<>();

	for(int i = 0; i < features.size(); i++){
		Feature feature = features.get(i);

		Number meanValue = (withMean ? mean.get(i) : 0d);
		Number stdValue = (withStd ? std.get(i) : 1d);

		if(ValueUtil.isZero(meanValue) && ValueUtil.isOne(stdValue)){
			result.add(feature);

			continue;
		}

		ContinuousFeature continuousFeature = feature.toContinuousFeature();

		// "($name - mean) / std"
		Expression expression = continuousFeature.ref();

		if(!ValueUtil.isZero(meanValue)){
			expression = PMMLUtil.createApply("-", expression, PMMLUtil.createConstant(meanValue));
		} // End if

		if(!ValueUtil.isOne(stdValue)){
			expression = PMMLUtil.createApply("/", expression, PMMLUtil.createConstant(stdValue));
		}

		DerivedField derivedField = encoder.createDerivedField(createName(continuousFeature), expression);

		result.add(new ContinuousFeature(encoder, derivedField));
	}

	return result;
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:49,代码来源:StandardScaler.java


注:本文中的org.jpmml.converter.PMMLUtil.createApply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。