本文整理汇总了Java中org.jpmml.converter.PMMLUtil类的典型用法代码示例。如果您正苦于以下问题:Java PMMLUtil类的具体用法?Java PMMLUtil怎么用?Java PMMLUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PMMLUtil类属于org.jpmml.converter包,在下文中一共展示了PMMLUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: encodeModel
import org.jpmml.converter.PMMLUtil; //导入依赖的package包/类
@Override
public ClusteringModel encodeModel(Schema schema){
KMeansModel model = getTransformer();
List<Cluster> clusters = new ArrayList<>();
Vector[] clusterCenters = model.clusterCenters();
for(int i = 0; i < clusterCenters.length; i++){
Cluster cluster = new Cluster()
.setId(String.valueOf(i))
.setArray(PMMLUtil.createRealArray(VectorUtil.toList(clusterCenters[i])));
clusters.add(cluster);
}
ComparisonMeasure comparisonMeasure = new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE)
.setCompareFunction(CompareFunction.ABS_DIFF)
.setMeasure(new SquaredEuclidean());
return new ClusteringModel(MiningFunction.CLUSTERING, ClusteringModel.ModelClass.CENTER_BASED, clusters.size(), ModelUtil.createMiningSchema(schema.getLabel()), comparisonMeasure, ClusteringModelUtil.createClusteringFields(schema.getFeatures()), clusters);
}
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:22,代码来源:KMeansModelConverter.java
示例3: 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
示例4: encodeIfElseExpression
import org.jpmml.converter.PMMLUtil; //导入依赖的package包/类
static
private Expression encodeIfElseExpression(FunctionExpression functionExpression, VariableMap expressionFields, RExpEncoder encoder){
FunctionExpression.Argument testArgument = functionExpression.getArgument("test", 0);
expressionFields.putAll(testArgument);
FunctionExpression.Argument yesArgument = functionExpression.getArgument("yes", 1);
FunctionExpression.Argument noArgument = functionExpression.getArgument("no", 2);
expressionFields.putAll(yesArgument);
expressionFields.putAll(noArgument);
// XXX: "Missing values in test give missing values in the result"
Apply apply = PMMLUtil.createApply("if")
.addExpressions(prepareExpression(testArgument, expressionFields, encoder))
.addExpressions(prepareExpression(yesArgument, expressionFields, encoder), prepareExpression(noArgument, expressionFields, encoder));
return apply;
}
开发者ID:jpmml,项目名称:jpmml-r,代码行数:20,代码来源:FormulaUtil.java
示例5: 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
示例6: 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
示例7: createApply
import org.jpmml.converter.PMMLUtil; //导入依赖的package包/类
@Override
public Apply createApply(){
Double weight = getWeight();
Apply apply = super.createApply()
.addExpressions(PMMLUtil.createConstant(weight));
return apply;
}
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:10,代码来源:WeightedTermFeature.java
示例8: 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
示例9: encodeApply
import org.jpmml.converter.PMMLUtil; //导入依赖的package包/类
@Override
public Apply encodeApply(String function, Feature feature, int index, String term){
TfidfTransformer transformer = getTransformer();
Apply apply = super.encodeApply(function, feature, index, term);
Boolean useIdf = transformer.getUseIdf();
if(useIdf){
Number weight = transformer.getWeight(index);
apply.addExpressions(PMMLUtil.createConstant(weight));
}
return apply;
}
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:16,代码来源:TfidfVectorizer.java
示例10: 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
示例11: encodeModel
import org.jpmml.converter.PMMLUtil; //导入依赖的package包/类
@Override
public ClusteringModel encodeModel(Schema schema){
int[] shape = getClusterCentersShape();
int numberOfClusters = shape[0];
int numberOfFeatures = shape[1];
List<? extends Number> clusterCenters = getClusterCenters();
List<Integer> labels = getLabels();
Multiset<Integer> labelCounts = HashMultiset.create();
if(labels != null){
labelCounts.addAll(labels);
}
List<Cluster> clusters = new ArrayList<>();
for(int i = 0; i < numberOfClusters; i++){
Cluster cluster = new Cluster()
.setId(String.valueOf(i))
.setSize((labelCounts.size () > 0 ? labelCounts.count(i) : null))
.setArray(PMMLUtil.createRealArray(CMatrixUtil.getRow(clusterCenters, numberOfClusters, numberOfFeatures, i)));
clusters.add(cluster);
}
ComparisonMeasure comparisonMeasure = new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE)
.setCompareFunction(CompareFunction.ABS_DIFF)
.setMeasure(new SquaredEuclidean());
ClusteringModel clusteringModel = new ClusteringModel(MiningFunction.CLUSTERING, ClusteringModel.ModelClass.CENTER_BASED, numberOfClusters, ModelUtil.createMiningSchema(schema.getLabel()), comparisonMeasure, ClusteringModelUtil.createClusteringFields(schema.getFeatures()), clusters)
.setOutput(ClusteringModelUtil.createOutput(FieldName.create("Cluster"), DataType.DOUBLE, clusters));
return clusteringModel;
}
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:37,代码来源:KMeans.java
示例12: createDiscrStats
import org.jpmml.converter.PMMLUtil; //导入依赖的package包/类
static
public DiscrStats createDiscrStats(Object[] objects){
List<Object> values = (List)asArray(objects[0]);
List<Integer> counts = ValueUtil.asIntegers((List)asArray(objects[1]));
ClassDictUtil.checkSize(values, counts);
DiscrStats discrStats = new DiscrStats()
.addArrays(PMMLUtil.createStringArray(values), PMMLUtil.createIntArray(counts));
return discrStats;
}
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:13,代码来源:CategoricalDomain.java
示例13: encodeModel
import org.jpmml.converter.PMMLUtil; //导入依赖的package包/类
@Override
public Model encodeModel(Schema schema){
RGenericVector kmeans = getObject();
RDoubleVector centers = (RDoubleVector)kmeans.getValue("centers");
RIntegerVector size = (RIntegerVector)kmeans.getValue("size");
RIntegerVector centersDim = centers.dim();
int rows = centersDim.getValue(0);
int columns = centersDim.getValue(1);
List<Cluster> clusters = new ArrayList<>();
RStringVector rowNames = centers.dimnames(0);
for(int i = 0; i < rowNames.size(); i++){
Cluster cluster = new Cluster()
.setId(String.valueOf(i + 1))
.setName(rowNames.getValue(i))
.setSize(size.getValue(i))
.setArray(PMMLUtil.createRealArray(FortranMatrixUtil.getRow(centers.getValues(), rows, columns, i)));
clusters.add(cluster);
}
ComparisonMeasure comparisonMeasure = new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE)
.setCompareFunction(CompareFunction.ABS_DIFF)
.setMeasure(new SquaredEuclidean());
ClusteringModel clusteringModel = new ClusteringModel(MiningFunction.CLUSTERING, ClusteringModel.ModelClass.CENTER_BASED, rows, ModelUtil.createMiningSchema(schema.getLabel()), comparisonMeasure, ClusteringModelUtil.createClusteringFields(schema.getFeatures()), clusters)
.setOutput(ClusteringModelUtil.createOutput(FieldName.create("cluster"), DataType.DOUBLE, clusters));
return clusteringModel;
}
开发者ID:jpmml,项目名称:jpmml-r,代码行数:35,代码来源:KMeansConverter.java
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: encodeFeatures
import org.jpmml.converter.PMMLUtil; //导入依赖的package包/类
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder){
Binarizer transformer = getTransformer();
Feature feature = encoder.getOnlyFeature(transformer.getInputCol());
ContinuousFeature continuousFeature = feature.toContinuousFeature();
Apply apply = new Apply("if")
.addExpressions(PMMLUtil.createApply("lessOrEqual", continuousFeature.ref(), PMMLUtil.createConstant(transformer.getThreshold())))
.addExpressions(PMMLUtil.createConstant(0d), PMMLUtil.createConstant(1d));
DerivedField derivedField = encoder.createDerivedField(formatName(transformer), OpType.CATEGORICAL, DataType.DOUBLE, apply);
return Collections.<Feature>singletonList(new CategoricalFeature(encoder, derivedField, Arrays.asList("0", "1")));
}
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:17,代码来源:BinarizerConverter.java
示例19: 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
示例20: 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
注:本文中的org.jpmml.converter.PMMLUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论