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


Java PMML.getModels方法代码示例

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


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

示例1: 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

示例2: selectModel

import org.dmg.pmml.PMML; //导入方法依赖的package包/类
static
protected <M extends Model> M selectModel(PMML pmml, Class<? extends M> clazz){

	if(!pmml.hasModels()){
		throw new MissingElementException(MissingElementException.formatMessage(XPathUtil.formatElement(pmml.getClass()) + "/" + XPathUtil.formatElement(clazz)), pmml);
	}

	List<Model> models = pmml.getModels();

	Iterable<? extends M> filteredModels = Iterables.filter(models, clazz);

	M model = Iterables.getFirst(filteredModels, null);
	if(model == null){
		throw new MissingElementException(MissingElementException.formatMessage(XPathUtil.formatElement(pmml.getClass()) + "/" + XPathUtil.formatElement(clazz)), pmml);
	}

	return model;
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:19,代码来源:ModelEvaluator.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 a decision forest
 * @param schema expected schema attributes of decision forest
 */
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);
  MiningFunction function = model.getMiningFunction();
  if (schema.isClassification()) {
    Preconditions.checkArgument(function == MiningFunction.CLASSIFICATION,
                                "Expected classification function type but got %s",
                                function);
  } else {
    Preconditions.checkArgument(function == MiningFunction.REGRESSION,
                                "Expected regression function type but got %s",
                                function);
  }

  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)));

  Integer pmmlIndex = AppPMMLUtils.findTargetIndex(miningSchema);
  if (schema.hasTarget()) {
    int schemaIndex = schema.getTargetFeatureIndex();
    Preconditions.checkArgument(
        pmmlIndex != null && schemaIndex == pmmlIndex,
        "Configured schema expects target at index %s, but PMML has target at index %s",
        schemaIndex, pmmlIndex);
  } else {
    Preconditions.checkArgument(pmmlIndex == null);
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:44,代码来源:RDFPMMLUtils.java

示例4: testReadWrite

import org.dmg.pmml.PMML; //导入方法依赖的package包/类
@Test
public void testReadWrite() throws Exception {
  Path tempModelFile = Files.createTempFile(getTempDir(), "model", ".pmml");
  PMML model = buildDummyModel();
  PMMLUtils.write(model, tempModelFile);
  assertTrue(Files.exists(tempModelFile));
  PMML model2 = PMMLUtils.read(tempModelFile);
  List<Model> models = model2.getModels();
  assertEquals(1, models.size());
  assertInstanceOf(models.get(0), TreeModel.class);
  TreeModel treeModel = (TreeModel) models.get(0);
  assertEquals(123.0, treeModel.getNode().getRecordCount().doubleValue());
  assertEquals(MiningFunction.CLASSIFICATION, treeModel.getMiningFunction());
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:15,代码来源:PMMLUtilsTest.java

示例5: compareModels

import org.dmg.pmml.PMML; //导入方法依赖的package包/类
public void compareModels(PMML model1, PMML model2) {
    assertThat(model1.getDataDictionary().getNumberOfFields(), equalTo(model2.getDataDictionary().getNumberOfFields()));
    int i = 0;
    for (DataField dataField : model1.getDataDictionary().getDataFields()) {
        DataField otherDataField = model2.getDataDictionary().getDataFields().get(i);
        assertThat(dataField.getDataType(), equalTo(otherDataField.getDataType()));
        assertThat(dataField.getName(), equalTo(otherDataField.getName()));
        i++;
    }

    assertThat(model1.getModels().size(), equalTo(model2.getModels().size()));
    i = 0;
    for (Model model : model1.getModels()) {
        if (model.getModelName().equals("linear SVM")) {
            assertThat(model, instanceOf(RegressionModel.class));
            assertThat(model2.getModels().get(i), instanceOf(RegressionModel.class));
            compareModels((RegressionModel) model, (RegressionModel) model2.getModels().get(i));
        } else if (model.getModelName().equals("logistic regression")) {
            assertThat(model, instanceOf(RegressionModel.class));
            assertThat(model2.getModels().get(i), instanceOf(RegressionModel.class));
            compareModels((RegressionModel) model, (RegressionModel) model2.getModels().get(i));
        } else {
            throw new UnsupportedOperationException("model " + model.getAlgorithmName() +
                    " is not supported and therfore not tested yet");
        }
        i++;
    }
}
 
开发者ID:brwe,项目名称:es-token-plugin,代码行数:29,代码来源:ModelTests.java

示例6: 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
	}
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:34,代码来源:ReflectionUtilTest.java

示例7: transform

import org.dmg.pmml.PMML; //导入方法依赖的package包/类
@Override
public PMML transform(PMML pmml){
	List<Model> models = pmml.getModels();

	for(Model model : models){

		if(model instanceof MiningModel){
			MiningModel miningModel = (MiningModel)model;

			transform(miningModel);
		}
	}

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

示例8: cleanChained

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

	DataDictionary dataDictionary = pmml.getDataDictionary();

	checkFields(FieldNameUtil.create("y", "x1", "x2", "x3", "x4"), dataDictionary.getDataFields());

	DataDictionaryCleaner cleaner = new DataDictionaryCleaner();
	cleaner.applyTo(pmml);

	checkFields(FieldNameUtil.create("y", "x1", "x2", "x3"), dataDictionary.getDataFields());

	List<Model> models = pmml.getModels();
	models.clear();

	cleaner.applyTo(pmml);

	checkFields(Collections.<FieldName>emptySet(), dataDictionary.getDataFields());
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:21,代码来源:DataDictionaryCleanerTest.java

示例9: cleanNested

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

	DataDictionary dataDictionary = pmml.getDataDictionary();

	checkFields(FieldNameUtil.create("y", "x1", "x2", "x3", "x4", "x5"), dataDictionary.getDataFields());

	DataDictionaryCleaner cleaner = new DataDictionaryCleaner();
	cleaner.applyTo(pmml);

	checkFields(FieldNameUtil.create("x1", "x2", "x3", "x4", "x5"), dataDictionary.getDataFields());

	List<Model> models = pmml.getModels();
	models.clear();

	cleaner.applyTo(pmml);

	checkFields(Collections.<FieldName>emptySet(), dataDictionary.getDataFields());
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:21,代码来源:DataDictionaryCleanerTest.java

示例10: filterChainedSegmentation

import org.dmg.pmml.PMML; //导入方法依赖的package包/类
@Test
public void filterChainedSegmentation() throws Exception {
	PMML pmml = ResourceUtil.unmarshal(ChainedSegmentationTest.class, new ElementFilter("Segmentation"));

	assertNotNull(pmml.getDataDictionary());
	assertNotNull(pmml.getTransformationDictionary());

	List<Model> models = pmml.getModels();

	MiningModel miningModel = (MiningModel)models.get(0);

	assertNotNull(miningModel.getMiningSchema());
	assertNotNull(miningModel.getOutput());

	assertNull(miningModel.getSegmentation());
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:17,代码来源:ElementFilterTest.java

示例11: filterNestedSegmentation

import org.dmg.pmml.PMML; //导入方法依赖的package包/类
@Test
public void filterNestedSegmentation() throws Exception {
	PMML pmml = ResourceUtil.unmarshal(NestedSegmentationTest.class, new ElementFilter(Segmentation.class));

	assertNotNull(pmml.getDataDictionary());

	List<Model> models = pmml.getModels();

	MiningModel miningModel = (MiningModel)models.get(0);

	assertNotNull(miningModel.getMiningSchema());
	assertNotNull(miningModel.getLocalTransformations());
	assertNotNull(miningModel.getOutput());

	assertNull(miningModel.getSegmentation());
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:17,代码来源:ElementFilterTest.java

示例12: newModelEvaluator

import org.dmg.pmml.PMML; //导入方法依赖的package包/类
public ModelEvaluator<? extends Model> newModelEvaluator(PMML pmml){

		if(!pmml.hasModels()){
			throw new MissingElementException(MissingElementException.formatMessage(XPathUtil.formatElement(pmml.getClass()) + "/<Model>"), pmml);
		}

		List<Model> models = pmml.getModels();

		Model model = models.get(0);

		return newModelEvaluator(pmml, model);
	}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:13,代码来源:ModelEvaluatorFactory.java


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