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


Java PMML类代码示例

本文整理汇总了Java中org.dmg.pmml.PMML的典型用法代码示例。如果您正苦于以下问题:Java PMML类的具体用法?Java PMML怎么用?Java PMML使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: buildModel

import org.dmg.pmml.PMML; //导入依赖的package包/类
/**
 * @param sparkContext    active Spark Context
 * @param trainData       training data on which to build a model
 * @param hyperParameters ordered list of hyper parameter values to use in building model
 * @param candidatePath   directory where additional model files can be written
 * @return a {@link PMML} representation of a model trained on the given data
 */
@Override
public PMML buildModel(JavaSparkContext sparkContext,
                       JavaRDD<String> trainData,
                       List<?> hyperParameters,
                       Path candidatePath) {
  int numClusters = (Integer) hyperParameters.get(0);
  Preconditions.checkArgument(numClusters > 1);
  log.info("Building KMeans Model with {} clusters", numClusters);

  JavaRDD<Vector> trainingData = parsedToVectorRDD(trainData.map(MLFunctions.PARSE_FN));
  KMeansModel kMeansModel = KMeans.train(trainingData.rdd(), numClusters, maxIterations,
                                         numberOfRuns, initializationStrategy);

  return kMeansModelToPMML(kMeansModel, fetchClusterCountsFromModel(trainingData, kMeansModel));
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:23,代码来源:KMeansUpdate.java

示例2: instantiateJPMMLModel

import org.dmg.pmml.PMML; //导入依赖的package包/类
private Evaluator instantiateJPMMLModel() {
  PMML pmml = null;
  try {
    pmml = IOUtil.unmarshal(Launcher.class.getResource("/predictionModel-PMML.xml").openStream());
  } catch (Exception e) {
    e.printStackTrace();
  }
  PMMLManager pmmlManager = new PMMLManager(pmml);
  Evaluator evaluator = (Evaluator) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
  return evaluator;
}
 
开发者ID:DhruvKumar,项目名称:iot-lab,代码行数:12,代码来源:SparkPredictionBolt.java

示例3: validatePMMLVsSchema

import org.dmg.pmml.PMML; //导入依赖的package包/类
/**
 * Validates that the encoded PMML model received matches expected schema.
 *
 * @param pmml {@link PMML} encoding of KMeans Clustering
 * @param schema expected schema attributes of KMeans Clustering
 */
public static void validatePMMLVsSchema(PMML pmml, InputSchema schema) {
  List<Model> models = pmml.getModels();
  Preconditions.checkArgument(models.size() == 1,
      "Should have exactly one model, but had %s", models.size());

  Model model = models.get(0);
  Preconditions.checkArgument(model instanceof ClusteringModel);
  Preconditions.checkArgument(model.getMiningFunction() == MiningFunction.CLUSTERING);

  DataDictionary dictionary = pmml.getDataDictionary();
  Preconditions.checkArgument(
      schema.getFeatureNames().equals(AppPMMLUtils.getFeatureNames(dictionary)),
      "Feature names in schema don't match names in PMML");

  MiningSchema miningSchema = model.getMiningSchema();
  Preconditions.checkArgument(schema.getFeatureNames().equals(
      AppPMMLUtils.getFeatureNames(miningSchema)));

}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:26,代码来源:KMeansPMMLUtils.java

示例4: consumeKeyMessage

import org.dmg.pmml.PMML; //导入依赖的package包/类
@Override
public void consumeKeyMessage(String key, String message, Configuration hadoopConf) throws IOException {
  switch (key) {
    case "UP":
      // do nothing, hearing our own updates
      break;
    case "MODEL":
    case "MODEL-REF":
      log.info("Loading new model");
      PMML pmml = AppPMMLUtils.readPMMLFromUpdateKeyMessage(key, message, hadoopConf);
      if (pmml == null) {
        return;
      }

      KMeansPMMLUtils.validatePMMLVsSchema(pmml, inputSchema);
      model = new KMeansSpeedModel(KMeansPMMLUtils.read(pmml));
      log.info("New model loaded: {}", model);
      break;
    default:
      throw new IllegalArgumentException("Bad key: " + key);
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:23,代码来源:KMeansSpeedModelManager.java

示例5: consumeKeyMessage

import org.dmg.pmml.PMML; //导入依赖的package包/类
@Override
public void consumeKeyMessage(String key, String message, Configuration hadoopConf) throws IOException {
  switch (key) {
    case "UP":
      // Nothing to do; just hearing our own updates
      break;
    case "MODEL":
    case "MODEL-REF":
      log.info("Loading new model");
      PMML pmml = AppPMMLUtils.readPMMLFromUpdateKeyMessage(key, message, hadoopConf);
      if (pmml == null) {
        return;
      }

      RDFPMMLUtils.validatePMMLVsSchema(pmml, inputSchema);
      Pair<DecisionForest,CategoricalValueEncodings> forestAndEncodings =
          RDFPMMLUtils.read(pmml);
      model = new RDFSpeedModel(forestAndEncodings.getFirst(), forestAndEncodings.getSecond());
      log.info("New model loaded: {}", model);
      break;
    default:
      throw new IllegalArgumentException("Bad key: " + key);
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:25,代码来源:RDFSpeedModelManager.java

示例6: generate

import org.dmg.pmml.PMML; //导入依赖的package包/类
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
  if (id % 10 == 0) {
    PMML pmml = PMMLUtils.buildSkeletonPMML();
    AppPMMLUtils.addExtension(pmml, "features", 2);
    AppPMMLUtils.addExtension(pmml, "implicit", true);
    AppPMMLUtils.addExtensionContent(pmml, "XIDs", X.keySet());
    AppPMMLUtils.addExtensionContent(pmml, "YIDs", Y.keySet());
    return new Pair<>("MODEL", PMMLUtils.toString(pmml));
  } else {
    int xOrYID = id % 10;
    String xOrYIDString = ALSUtilsTest.idToStringID(id);
    String message;
    boolean isX = xOrYID >= 6;
    if (isX) {
      message = TextUtils.joinJSON(Arrays.asList(
          "X", xOrYIDString, X.get(xOrYIDString), A.get(xOrYIDString)));
    } else {
      message = TextUtils.joinJSON(Arrays.asList(
          "Y", xOrYIDString, Y.get(xOrYIDString), At.get(xOrYIDString)));
    }
    return new Pair<>("UP", message);
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:25,代码来源:MockALSModelUpdateGenerator.java

示例7: testPreviousPMMLVersion

import org.dmg.pmml.PMML; //导入依赖的package包/类
@Test
public void testPreviousPMMLVersion() throws Exception {
  String pmml42 =
      "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
      "<PMML xmlns=\"http://www.dmg.org/PMML-4_2\" version=\"4.2.1\">\n" +
      "    <Header>\n" +
      "        <Application name=\"Oryx\"/>\n" +
      "    </Header>\n" +
      "    <TreeModel functionName=\"classification\">\n" +
      "        <Node recordCount=\"123.0\"/>\n" +
      "    </TreeModel>\n" +
      "</PMML>\n";
  PMML model = PMMLUtils.fromString(pmml42);
  // Actually transforms to latest version:
  assertEquals(PMMLUtils.VERSION, model.getVersion());
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:17,代码来源:PMMLUtilsTest.java

示例8: run

import org.dmg.pmml.PMML; //导入依赖的package包/类
private void run() throws Exception {
	Learner learner;

	try(InputStream is = new FileInputStream(this.modelInput)){
		learner = XGBoostUtil.loadLearner(is);
	}

	FeatureMap featureMap;

	try(InputStream is = new FileInputStream(this.fmapInput)){
		featureMap = XGBoostUtil.loadFeatureMap(is);
	}

	if(this.missingValue != null){
		featureMap.addMissingValue(this.missingValue);
	}

	PMML pmml = learner.encodePMML(this.targetName != null ? FieldName.create(this.targetName) : null, this.targetCategories, featureMap, this.ntreeLimit, this.transform);

	try(OutputStream os = new FileOutputStream(this.pmmlOutput)){
		MetroJAXBUtil.marshalPMML(pmml, os);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-xgboost,代码行数:24,代码来源:Main.java

示例9: testTreeModelOnActualLookup

import org.dmg.pmml.PMML; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testTreeModelOnActualLookup() throws Exception {
    ModelFactories parser = ModelFactories.createDefaultModelFactories();
    DataSource dataSource = createTestDataSource(new String[]{"Self-emp-inc"}, "Prof-school", 60);
    final String pmmlString = copyToStringFromClasspath("/org/elasticsearch/script/tree-small-r.xml");
    PMML pmml = ProcessPMMLHelper.parsePmml(pmmlString);
    ModelAndModelInputEvaluator<MapModelInput, String> fieldsToVectorAndModel = parser.buildFromPMML(pmml, 0);
    ModelInputEvaluator<MapModelInput> vectorEntries = fieldsToVectorAndModel.getVectorRangesToVector();
    Map<String, Object> vector = vectorEntries.convert(dataSource).getAsMap();
    assertThat(vector.size(), equalTo(3));
    assertThat(((Number)((Set) vector.get("age_z")).iterator().next()).doubleValue(), closeTo(1.5702107070685085, 0.0));
    assertThat(((Set) vector.get("education")).iterator().next(), equalTo("Prof-school"));
    assertThat(((Set) vector.get("work")).iterator().next(), equalTo("Self-emp-inc"));

    // test missing values
    dataSource = createTestDataSource(null, null, null);
    vector = vectorEntries.convert(dataSource).getAsMap();
    assertThat(vector.size(), equalTo(3));
    assertThat(((Number)((Set) vector.get("age_z")).iterator().next()).doubleValue(), closeTo(-76.13993490863606, 0.0));
    assertThat(((Set) vector.get("education")).iterator().next(), equalTo("too-lazy-to-study"));
    assertThat(((Set) vector.get("work")).iterator().next(), equalTo("other"));
}
 
开发者ID:brwe,项目名称:es-token-plugin,代码行数:23,代码来源:VectorizerPMMLSingleNodeTests.java

示例10: newModelRunner

import org.dmg.pmml.PMML; //导入依赖的package包/类
@Override
public ModelRunner newModelRunner() {
    final ModelProcessor modelProcessor = Utils.createObjectFromJson(modelProcessorJson, ModelProcessor.class);
    PMML pmmlModel;
    try {
        pmmlModel = JpmmlFactory.newPmml(
                new ByteArrayInputStream(modelProcessor.getPmml().getBytes()));
    } catch (Exception e) {
        throw new RuntimeException("Exception occurred while creating PMML model object", e);
    }

    return new StreamlineJPMMLModelRunner(
            modelProcessor.getOutputStreams(),
            modelProcessor.getId(),
            JpmmlFactory.newEvaluator(pmmlModel),
            modelOutputs);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:18,代码来源:StreamlineJPMMLModelRunnerFactory.java

示例11: encodePMML

import org.dmg.pmml.PMML; //导入依赖的package包/类
@Override
public PMML encodePMML(){
	RGenericVector train = getObject();

	RExp finalModel = train.getValue("finalModel");
	RGenericVector preProcess = (RGenericVector)train.getValue("preProcess");

	ConverterFactory converterFactory = ConverterFactory.newInstance();

	ModelConverter<RExp> converter = (ModelConverter<RExp>)converterFactory.newConverter(finalModel);

	RExpEncoder encoder;

	if(preProcess != null){
		encoder = new PreProcessEncoder(preProcess);
	} else

	{
		encoder = new RExpEncoder();
	}

	return converter.encodePMML(encoder);
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:24,代码来源:TrainConverter.java

示例12: convert

import org.dmg.pmml.PMML; //导入依赖的package包/类
static
private PMML convert(RExp rexp, Class<? extends Converter<? extends RExp>> clazz) throws Exception {
	ConverterFactory converterFactory = ConverterFactory.newInstance();

	Converter<RExp> converter;

	if(clazz != null){
		converter = converterFactory.newConverter(clazz, rexp);
	} else

	{
		converter = converterFactory.newConverter(rexp);
	}

	return converter.encodePMML();
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:17,代码来源:ConverterTest.java

示例13: createTreeModelEvaluator

import org.dmg.pmml.PMML; //导入依赖的package包/类
static
private TreeModelEvaluator createTreeModelEvaluator(MiningFunction miningFunction, MathContext mathContext, Target target){
	Node root = new Node()
		.setPredicate(new False());

	Targets targets = new Targets()
		.addTargets(target);

	TreeModel treeModel = new TreeModel(miningFunction, new MiningSchema(), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
		.setMathContext(mathContext)
		.setTargets(targets);

	PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), new DataDictionary())
		.addModels(treeModel);

	return new TreeModelEvaluator(pmml);
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:19,代码来源:TargetUtilTest.java

示例14: popParent

import org.dmg.pmml.PMML; //导入依赖的package包/类
@Override
public PMMLObject popParent(){
	PMMLObject parent = super.popParent();

	if(parent instanceof Model){
		Model model = (Model)parent;

		processModel(model);
	} else

	if(parent instanceof PMML){
		PMML pmml = (PMML)parent;

		DataDictionary dataDictionary = pmml.getDataDictionary();
		if(dataDictionary != null){
			processDataDictionary(dataDictionary);
		}
	}

	return parent;
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:22,代码来源:DataDictionaryCleaner.java

示例15: mixedContent

import org.dmg.pmml.PMML; //导入依赖的package包/类
@Test
public void mixedContent() throws Exception {
	PMML pmml = ResourceUtil.unmarshal(getClass());

	List<?> content = ExtensionUtil.getContent(pmml);

	assertEquals(5, content.size());

	assertEquals("First text value", content.get(0));
	assertEquals(Arrays.asList("First extension"), getDeepContent(content.get(1)));
	assertEquals("Second text value", content.get(2));
	assertEquals(Arrays.asList("Second extension"), getDeepContent(content.get(3)));
	assertEquals("Third text value", content.get(4));

	try {
		SerializationUtil.clone(pmml);

		fail();
	} catch(NotSerializableException nse){
		// Ignored
	}

	pmml.accept(new LocatorTransformer());

	SerializationUtil.clone(pmml);
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:27,代码来源:MixedContentTest.java


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