/** * 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))); }
MiningFunction function = model.getMiningFunction(); if (schema.isClassification()) { Preconditions.checkArgument(function == MiningFunction.CLASSIFICATION,
@Test public void testFromString() throws Exception { PMML model = buildDummyModel(); PMML model2 = PMMLUtils.fromString(PMMLUtils.toString(model)); assertEquals(model.getHeader().getApplication().getName(), model2.getHeader().getApplication().getName()); assertEquals(model.getModels().get(0).getMiningFunction(), model2.getModels().get(0).getMiningFunction()); }
assertEquals(MiningFunction.CLASSIFICATION, rootModel.getMiningFunction()); } else { assertEquals(MiningFunction.REGRESSION, rootModel.getMiningFunction());
@Override public MiningFunction getMiningFunction(){ M model = getModel(); return model.getMiningFunction(); }
private <V extends Number> Map<FieldName, ?> evaluateDefault(){ Model model = getModel(); MiningFunction miningFunction = model.getMiningFunction(); throw new InvalidAttributeException(model, miningFunction); }
@Override public VisitorAction visit(Model model){ MiningFunction miningFunction = model.getMiningFunction(); switch(miningFunction){ case REGRESSION: processRegressionModel(model); break; default: break; } return super.visit(model); }
/** * 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))); }
static public MiningModel createModelChain(List<? extends Model> models, Schema schema){ if(models.size() < 1){ throw new IllegalArgumentException(); } Segmentation segmentation = createSegmentation(Segmentation.MultipleModelMethod.MODEL_CHAIN, models); Model lastModel = Iterables.getLast(models); MiningModel miningModel = new MiningModel(lastModel.getMiningFunction(), ModelUtil.createMiningSchema(schema.getLabel())) .setMathContext(ModelUtil.simplifyMathContext(lastModel.getMathContext())) .setSegmentation(segmentation); return miningModel; }
static private void checkMiningFunction(Model model, MiningFunction parentMiningFunction){ MiningFunction miningFunction = model.getMiningFunction(); if(miningFunction == null){ throw new MissingAttributeException(MissingAttributeException.formatMessage(XPathUtil.formatElement(model.getClass()) + "@functionName"), model); } // End if if(!(miningFunction).equals(parentMiningFunction)){ throw new InvalidAttributeException(InvalidAttributeException.formatMessage(XPathUtil.formatElement(model.getClass()) + "@functionName=" + miningFunction.value()), model); } }
MiningFunction function = model.getMiningFunction(); if (schema.isClassification()) { Preconditions.checkArgument(function == MiningFunction.CLASSIFICATION,
if((transformer instanceof GeneralizedLinearRegressionModel) && (MiningFunction.CLASSIFICATION).equals(model.getMiningFunction())){ break hasPredictionCol;
MiningFunction miningFunction = segmentModel.getMiningFunction(); switch(miningFunction){ case REGRESSION:
MiningFunction miningFunction = model.getMiningFunction(); if(miningFunction == null){ throw new MissingAttributeException(MissingAttributeException.formatMessage(XPathUtil.formatElement(model.getClass()) + "@functionName"), model);
public JavaModel(Model model){ setModelName(model.getModelName()); setMiningFunction(model.getMiningFunction()); setAlgorithmName(model.getAlgorithmName()); setScorable(model.isScorable()); setMathContext(model.getMathContext()); setMiningSchema(model.getMiningSchema()); setOutput(model.getOutput()); setModelStats(model.getModelStats()); setModelExplanation(model.getModelExplanation()); setTargets(model.getTargets()); setLocalTransformations(model.getLocalTransformations()); setModelVerification(model.getModelVerification()); }
MiningFunction miningFunction = model.getMiningFunction(); switch(miningFunction){ case REGRESSION: