本文整理汇总了Java中org.dmg.pmml.PMML.setDataDictionary方法的典型用法代码示例。如果您正苦于以下问题:Java PMML.setDataDictionary方法的具体用法?Java PMML.setDataDictionary怎么用?Java PMML.setDataDictionary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dmg.pmml.PMML
的用法示例。
在下文中一共展示了PMML.setDataDictionary方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: kMeansModelToPMML
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
/**
* @param model {@link KMeansModel} to translate to PMML
* @return PMML representation of a KMeans cluster model
*/
private PMML kMeansModelToPMML(KMeansModel model, Map<Integer,Long> clusterSizesMap) {
ClusteringModel clusteringModel = pmmlClusteringModel(model, clusterSizesMap);
PMML pmml = PMMLUtils.buildSkeletonPMML();
pmml.setDataDictionary(AppPMMLUtils.buildDataDictionary(inputSchema, null));
pmml.addModels(clusteringModel);
return pmml;
}
示例2: generateSVMPMMLModel
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
public static String generateSVMPMMLModel(double intercept, double[] weights, double[] labels) throws JAXBException,
UnsupportedEncodingException {
PMML pmml = new PMML();
// create DataDictionary
DataDictionary dataDictionary = createDataDictionary(weights);
pmml.setDataDictionary(dataDictionary);
// create model
RegressionModel regressionModel = new RegressionModel();
regressionModel.setModelName("linear SVM");
regressionModel.setFunctionName(MiningFunctionType.CLASSIFICATION);
regressionModel.setNormalizationMethod(RegressionNormalizationMethodType.NONE);
MiningSchema miningSchema = createMiningSchema(weights);
regressionModel.setMiningSchema(miningSchema);
RegressionTable regressionTable0 = new RegressionTable();
regressionTable0.setIntercept(intercept);
regressionTable0.setTargetCategory(Double.toString(labels[0]));
NumericPredictor[] numericPredictors = createNumericPredictors(weights);
regressionTable0.addNumericPredictors(numericPredictors);
RegressionTable regressionTable1 = new RegressionTable();
regressionTable1.setIntercept(0.0);
regressionTable1.setTargetCategory(Double.toString(labels[1]));
regressionModel.addRegressionTables(regressionTable0, regressionTable1);
pmml.addModels(regressionModel);
// marshal
return convertPMMLToString(pmml);
// write to string
}
示例3: generateLRPMMLModel
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
public static String generateLRPMMLModel(double intercept, double[] weights, double[] labels) throws JAXBException,
UnsupportedEncodingException {
PMML pmml = new PMML();
// create DataDictionary
DataDictionary dataDictionary = createDataDictionary(weights);
pmml.setDataDictionary(dataDictionary);
// create model
RegressionModel regressionModel = new RegressionModel();
regressionModel.setModelName("logistic regression");
regressionModel.setFunctionName(MiningFunctionType.CLASSIFICATION);
regressionModel.setNormalizationMethod(RegressionNormalizationMethodType.LOGIT);
MiningSchema miningSchema = createMiningSchema(weights);
regressionModel.setMiningSchema(miningSchema);
RegressionTable regressionTable0 = new RegressionTable();
regressionTable0.setIntercept(intercept);
regressionTable0.setTargetCategory(Double.toString(labels[0]));
NumericPredictor[] numericPredictors = createNumericPredictors(weights);
regressionTable0.addNumericPredictors(numericPredictors);
RegressionTable regressionTable1 = new RegressionTable();
regressionTable1.setIntercept(0.0);
regressionTable1.setTargetCategory(Double.toString(labels[1]));
regressionModel.addRegressionTables(regressionTable0, regressionTable1);
pmml.addModels(regressionModel);
// marshal
return convertPMMLToString(pmml);
// write to string
}
示例4: buildDummyClusteringModel
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
public static PMML buildDummyClusteringModel() {
PMML pmml = PMMLUtils.buildSkeletonPMML();
List<DataField> dataFields = new ArrayList<>();
dataFields.add(new DataField(FieldName.create("x"), OpType.CONTINUOUS, DataType.DOUBLE));
dataFields.add(new DataField(FieldName.create("y"), OpType.CONTINUOUS, DataType.DOUBLE));
DataDictionary dataDictionary =
new DataDictionary(dataFields).setNumberOfFields(dataFields.size());
pmml.setDataDictionary(dataDictionary);
List<MiningField> miningFields = new ArrayList<>();
MiningField xMF = new MiningField(FieldName.create("x"))
.setOpType(OpType.CONTINUOUS).setUsageType(MiningField.UsageType.ACTIVE);
miningFields.add(xMF);
MiningField yMF = new MiningField(FieldName.create("y"))
.setOpType(OpType.CONTINUOUS).setUsageType(MiningField.UsageType.ACTIVE);
miningFields.add(yMF);
MiningSchema miningSchema = new MiningSchema(miningFields);
List<ClusteringField> clusteringFields = new ArrayList<>();
clusteringFields.add(new ClusteringField(
FieldName.create("x")).setCenterField(ClusteringField.CenterField.TRUE));
clusteringFields.add(new ClusteringField(
FieldName.create("y")).setCenterField(ClusteringField.CenterField.TRUE));
List<Cluster> clusters = new ArrayList<>();
clusters.add(new Cluster().setId("0").setSize(1).setArray(AppPMMLUtils.toArray(1.0, 0.0)));
clusters.add(new Cluster().setId("1").setSize(2).setArray(AppPMMLUtils.toArray(2.0, -1.0)));
clusters.add(new Cluster().setId("2").setSize(3).setArray(AppPMMLUtils.toArray(-1.0, 0.0)));
pmml.addModels(new ClusteringModel(
MiningFunction.CLUSTERING,
ClusteringModel.ModelClass.CENTER_BASED,
clusters.size(),
miningSchema,
new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE).setMeasure(new SquaredEuclidean()),
clusteringFields,
clusters));
return pmml;
}
示例5: buildDummyClassificationModel
import org.dmg.pmml.PMML; //导入方法依赖的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;
}
示例6: buildDummyRegressionModel
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
public static PMML buildDummyRegressionModel() {
PMML pmml = PMMLUtils.buildSkeletonPMML();
List<DataField> dataFields = new ArrayList<>();
dataFields.add(new DataField(FieldName.create("foo"), OpType.CONTINUOUS, DataType.DOUBLE));
dataFields.add(new DataField(FieldName.create("bar"), OpType.CONTINUOUS, DataType.DOUBLE));
DataDictionary dataDictionary =
new DataDictionary(dataFields).setNumberOfFields(dataFields.size());
pmml.setDataDictionary(dataDictionary);
List<MiningField> miningFields = new ArrayList<>();
MiningField predictorMF = new MiningField(FieldName.create("foo"))
.setOpType(OpType.CONTINUOUS)
.setUsageType(MiningField.UsageType.ACTIVE)
.setImportance(0.5);
miningFields.add(predictorMF);
MiningField targetMF = new MiningField(FieldName.create("bar"))
.setOpType(OpType.CONTINUOUS)
.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())
.setScore("-2.0");
Node right = new Node().setId("r+").setRecordCount(halfCount)
.setPredicate(new SimplePredicate(FieldName.create("foo"),
SimplePredicate.Operator.GREATER_THAN).setValue("3.14"))
.setScore("2.0");
rootNode.addNodes(right, left);
TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, miningSchema, rootNode)
.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
.setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD)
.setMiningSchema(miningSchema);
pmml.addModels(treeModel);
return pmml;
}
示例7: rdfModelToPMML
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
private PMML rdfModelToPMML(RandomForestModel rfModel,
CategoricalValueEncodings categoricalValueEncodings,
int maxDepth,
int maxSplitCandidates,
String impurity,
List<Map<Integer,Long>> nodeIDCounts,
Map<Integer,Long> predictorIndexCounts) {
boolean classificationTask = rfModel.algo().equals(Algo.Classification());
Preconditions.checkState(classificationTask == inputSchema.isClassification());
DecisionTreeModel[] trees = rfModel.trees();
Model model;
if (trees.length == 1) {
model = toTreeModel(trees[0], categoricalValueEncodings, nodeIDCounts.get(0));
} else {
MiningModel miningModel = new MiningModel();
model = miningModel;
Segmentation.MultipleModelMethod multipleModelMethodType = classificationTask ?
Segmentation.MultipleModelMethod.WEIGHTED_MAJORITY_VOTE :
Segmentation.MultipleModelMethod.WEIGHTED_AVERAGE;
List<Segment> segments = new ArrayList<>(trees.length);
for (int treeID = 0; treeID < trees.length; treeID++) {
TreeModel treeModel =
toTreeModel(trees[treeID], categoricalValueEncodings, nodeIDCounts.get(treeID));
segments.add(new Segment()
.setId(Integer.toString(treeID))
.setPredicate(new True())
.setModel(treeModel)
.setWeight(1.0)); // No weights in MLlib impl now
}
miningModel.setSegmentation(new Segmentation(multipleModelMethodType, segments));
}
model.setMiningFunction(classificationTask ?
MiningFunction.CLASSIFICATION :
MiningFunction.REGRESSION);
double[] importances = countsToImportances(predictorIndexCounts);
model.setMiningSchema(AppPMMLUtils.buildMiningSchema(inputSchema, importances));
DataDictionary dictionary =
AppPMMLUtils.buildDataDictionary(inputSchema, categoricalValueEncodings);
PMML pmml = PMMLUtils.buildSkeletonPMML();
pmml.setDataDictionary(dictionary);
pmml.addModels(model);
AppPMMLUtils.addExtension(pmml, "maxDepth", maxDepth);
AppPMMLUtils.addExtension(pmml, "maxSplitCandidates", maxSplitCandidates);
AppPMMLUtils.addExtension(pmml, "impurity", impurity);
return pmml;
}