本文整理汇总了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)));
}
示例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;
}
示例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);
}
}
示例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());
}
示例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++;
}
}
示例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
}
}
示例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;
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}