本文整理汇总了Java中org.dmg.pmml.PMML.addModels方法的典型用法代码示例。如果您正苦于以下问题:Java PMML.addModels方法的具体用法?Java PMML.addModels怎么用?Java PMML.addModels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dmg.pmml.PMML
的用法示例。
在下文中一共展示了PMML.addModels方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildDummyModel
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
private static PMML buildDummyModel() {
Node node = new Node().setRecordCount(123.0);
TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, null, node);
PMML pmml = PMMLUtils.buildSkeletonPMML();
pmml.addModels(treeModel);
return pmml;
}
示例2: 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;
}
示例3: buildDummyModel
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
public static PMML buildDummyModel() {
Node node = new Node().setRecordCount(123.0);
TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, null, node);
PMML pmml = PMMLUtils.buildSkeletonPMML();
pmml.addModels(treeModel);
return pmml;
}
示例4: 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
}
示例5: 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
}
示例6: encodePMML
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
public PMML encodePMML(Model model){
PMML pmml = encodePMML();
pmml.addModels(model);
List<? extends Visitor> visitors = Arrays.asList(new MiningSchemaCleaner(), new TransformationDictionaryCleaner(), new DataDictionaryCleaner());
for(Visitor visitor : visitors){
visitor.applyTo(pmml);
}
MiningSchema miningSchema = model.getMiningSchema();
List<MiningField> miningFields = miningSchema.getMiningFields();
for(MiningField miningField : miningFields){
FieldName name = miningField.getName();
List<Decorator> decorators = getDecorators(name);
if(decorators == null){
continue;
}
DataField dataField = getDataField(name);
if(dataField == null){
throw new IllegalArgumentException();
}
for(Decorator decorator : decorators){
decorator.decorate(dataField, miningField);
}
}
Collection<Map.Entry<FieldName, FieldName>> entries = this.renamedFields.entrySet();
for(Map.Entry<FieldName, FieldName> entry : entries){
FieldRenamer renamer = new FieldRenamer(entry.getKey(), entry.getValue());
renamer.applyTo(pmml);
}
return pmml;
}
示例7: copyState
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
@Test
public void copyState(){
PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), new DataDictionary());
// Initialize the live list instance
pmml.getModels();
CustomPMML customPmml = new CustomPMML();
ReflectionUtil.copyState(pmml, customPmml);
assertSame(pmml.getVersion(), customPmml.getVersion());
assertSame(pmml.getHeader(), customPmml.getHeader());
assertSame(pmml.getDataDictionary(), customPmml.getDataDictionary());
assertFalse(pmml.hasModels());
assertFalse(customPmml.hasModels());
pmml.addModels(new RegressionModel());
assertTrue(pmml.hasModels());
assertTrue(customPmml.hasModels());
assertSame(pmml.getModels(), customPmml.getModels());
try {
ReflectionUtil.copyState(customPmml, pmml);
fail();
} catch(IllegalArgumentException iae){
// Ignored
}
}
示例8: inspectTypeAnnotations
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
@Test
public void inspectTypeAnnotations(){
PMML pmml = createPMML();
assertVersionRange(pmml, Version.PMML_3_0, Version.PMML_4_3);
pmml.addModels(new AssociationModel(),
//new ClusteringModel(),
//new GeneralRegressionModel(),
//new MiningModel(),
new NaiveBayesModel(),
new NeuralNetwork(),
new RegressionModel(),
new RuleSetModel(),
new SequenceModel(),
//new SupportVectorMachineModel(),
new TextModel(),
new TreeModel());
assertVersionRange(pmml, Version.PMML_3_0, Version.PMML_4_3);
pmml.addModels(new TimeSeriesModel());
assertVersionRange(pmml, Version.PMML_4_0, Version.PMML_4_3);
pmml.addModels(new BaselineModel(),
new Scorecard(),
new NearestNeighborModel());
assertVersionRange(pmml, Version.PMML_4_1, Version.PMML_4_3);
pmml.addModels(new BayesianNetworkModel(),
new GaussianProcessModel());
assertVersionRange(pmml, Version.PMML_4_3, Version.PMML_4_3);
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: inspectFieldAnnotations
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
@Test
public void inspectFieldAnnotations(){
PMML pmml = createPMML();
AssociationModel model = new AssociationModel();
pmml.addModels(model);
assertVersionRange(pmml, Version.PMML_3_0, Version.PMML_4_3);
Output output = new Output();
model.setOutput(output);
assertVersionRange(pmml, Version.PMML_4_0, Version.PMML_4_3);
model.setScorable(Boolean.FALSE);
assertVersionRange(pmml, Version.PMML_4_1, Version.PMML_4_3);
model.setScorable(null);
assertVersionRange(pmml, Version.PMML_4_0, Version.PMML_4_3);
OutputField outputField = new OutputField()
.setRuleFeature(OutputField.RuleFeature.AFFINITY);
output.addOutputFields(outputField);
assertVersionRange(pmml, Version.PMML_4_1, Version.PMML_4_2);
outputField.setDataType(DataType.DOUBLE);
assertVersionRange(pmml, Version.PMML_4_1, Version.PMML_4_3);
model.setOutput(null);
assertVersionRange(pmml, Version.PMML_3_0, Version.PMML_4_3);
}
示例14: inspectValueAnnotations
import org.dmg.pmml.PMML; //导入方法依赖的package包/类
@Test
public void inspectValueAnnotations(){
PMML pmml = createPMML();
FieldName name = FieldName.create("y");
Target target = new Target()
.setField(name)
.addTargetValues(createTargetValue("no event"), createTargetValue("event"));
Targets targets = new Targets()
.addTargets(target);
GeneralRegressionModel model = new GeneralRegressionModel()
.setTargets(targets);
pmml.addModels(model);
assertVersionRange(pmml, Version.PMML_3_0, Version.PMML_3_0);
PPMatrix ppMatrix = new PPMatrix()
.addPPCells(new PPCell(), new PPCell());
model.setPPMatrix(ppMatrix);
assertVersionRange(pmml, Version.PMML_3_0, Version.PMML_4_3);
target.setField(null);
assertVersionRange(pmml, Version.PMML_4_3, Version.PMML_4_3);
}