PMML pmml = new PMML(); pmml.setVersion(PMML_VERSION); Header header = new Header(); Timestamp timestamp = new Timestamp(); header.getExtensions().add(agendaGroupExt); pmml.setHeader(header); pmml.getAssociationModelsAndBaselineModelsAndClusteringModels().add(pmmlScorecard); removeAttributeFieldExtension(pmmlScorecard); return pmml;
protected PMMLResource buildResourceFromSegment(PMML pmml_origin, MiningSegment segment, ClassLoader classLoader, KieModuleModel module) { PMML pmml = new PMML(); DataDictionary dd = pmml_origin.getDataDictionary(); pmml.setDataDictionary(dd); pmml.setHeader(pmml_origin.getHeader()); pmml.getAssociationModelsAndBaselineModelsAndClusteringModels().add(segment.getModel().getRawModel()); addMissingFieldDefinition(pmml, segment.getOwner(), segment); helper.setPack(segment.getModel().getModelPackageName());//PMML4Helper.pmmlDefaultPackageName()+".mining.segment_"+segment.getSegmentId()); StringBuilder rules = new StringBuilder(this.compile(pmml, classLoader)); String extBeanMiningRules = segment.getModel().getExternalBeansMiningRules(); if (extBeanMiningRules != null) { rules.append(extBeanMiningRules); } KieBaseModel kbModel = module.newKieBaseModel(segment.getOwner().getOwner().getModelId() + "_" + segment.getOwner().getSegmentationId() + "_SEGMENT_" + segment.getSegmentId()); kbModel.addPackage(helper.getPack()) .setDefault(false) .setEventProcessingMode(EventProcessingOption.CLOUD); KieSessionModel ksm = kbModel.newKieSessionModel("SEGMENT_" + segment.getSegmentId()); ksm.setDefault(true); PMMLResource resource = new PMMLResource(helper.getPack()); resource.setKieBaseModel(kbModel); resource.addRules(segment.getModel().getModelId(), rules.toString()); return resource; }
public List<PMML4Model> getModels(PMML4Unit owner) { List<PMML4Model> pmml4Models = new ArrayList<>(); owner.getRawPMML().getAssociationModelsAndBaselineModelsAndClusteringModels() .forEach(serializable -> { if (serializable instanceof Scorecard) { Scorecard sc = (Scorecard) serializable; ScorecardModel model = new ScorecardModel(sc.getModelName(), sc, null, owner); pmml4Models.add(model); } else if (serializable instanceof RegressionModel) { RegressionModel rm = (RegressionModel) serializable; Regression model = new Regression(rm.getModelName(), rm, null, owner); pmml4Models.add(model); } else if (serializable instanceof TreeModel) { TreeModel tm = (TreeModel) serializable; Treemodel model = new Treemodel(tm.getModelName(), tm, null, owner); pmml4Models.add(model); } else if (serializable instanceof MiningModel) { MiningModel mm = (MiningModel) serializable; Miningmodel model = new Miningmodel(mm.getModelName(), mm, null, owner); pmml4Models.add(model); } }); return pmml4Models; } }
assertEquals( inputfieldNames.length + outputfieldNames.length, net2.getDataDictionary().getDataFields().size() ); assertEquals( net.getDataDictionary().getDataFields().size(), net2.getDataDictionary().getDataFields().size() ); NeuralNetwork n1 = (NeuralNetwork) net.getAssociationModelsAndBaselineModelsAndClusteringModels().get( 0 ); NeuralNetwork n2 = (NeuralNetwork) net2.getAssociationModelsAndBaselineModelsAndClusteringModels().get( 0 );
/** * Initializes the internal structure that holds data dictionary information. * This initializer should be called prior to any other initializers, since * many other structures may have a dependency on the data dictionary. */ private void initDataDictionaryMap() { DataDictionary dd = rawPmml.getDataDictionary(); if (dd != null) { dataDictionaryMap = new HashMap<>(); for (DataField dataField : dd.getDataFields()) { PMMLDataField df = new PMMLDataField(dataField); dataDictionaryMap.put(df.getName(), df); } } else { throw new IllegalStateException("BRMS-PMML requires a data dictionary section in the definition file"); } }
/** * Create an instance of {@link PMML } * */ public PMML createPMML() { return new PMML(); }
private void createAndSetDataDictionary(PMML pmml, Scorecard pmmlScorecard) { pmml.setDataDictionary(dataDictionary); int ctr = 0; for (Object obj : pmmlScorecard.getExtensionsAndCharacteristicsAndMiningSchemas()) {
private void checkCharacteristics(PMML pmml) { if (pmml != null && pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() != null && !pmml.getAssociationModelsAndBaselineModelsAndClusteringModels().isEmpty()) { for (Serializable s : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels()) { if (s instanceof Scorecard) { Scorecard scard = (Scorecard) s; if (scard.getExtensionsAndCharacteristicsAndMiningSchemas() != null && !scard.getExtensionsAndCharacteristicsAndMiningSchemas().isEmpty()) { for (Serializable sz : scard.getExtensionsAndCharacteristicsAndMiningSchemas()) { if (sz instanceof Characteristics) { Characteristics characteristics = (Characteristics) sz; if (characteristics.getCharacteristics() == null || characteristics.getCharacteristics().isEmpty()) { Characteristic ch = new Characteristic(); ch.setBaselineScore(0.0); ch.setName("placeholder"); Attribute attr = new Attribute(); attr.setFalse(new False()); ch.getAttributes().add(attr); characteristics.getCharacteristics().add(ch); } } } } } } } } }
assertEquals( inputfieldNames.length + outputfieldNames.length, net2.getDataDictionary().getDataFields().size() ); assertEquals( net.getDataDictionary().getDataFields().size(), net2.getDataDictionary().getDataFields().size() ); NeuralNetwork n1 = (NeuralNetwork) net.getAssociationModelsAndBaselineModelsAndClusteringModels().get( 0 ); NeuralNetwork n2 = (NeuralNetwork) net2.getAssociationModelsAndBaselineModelsAndClusteringModels().get( 0 );
public static String getDataType(PMML pmmlDocument, String fieldName) { DataDictionary dataDictionary = pmmlDocument.getDataDictionary(); for (DataField dataField : dataDictionary.getDataFields()){ if (dataField.getName().equalsIgnoreCase(fieldName)) { DATATYPE datatype = dataField.getDataType(); if (datatype == DATATYPE.DOUBLE) { return XLSKeywords.DATATYPE_NUMBER; } else if (datatype == DATATYPE.STRING) { return XLSKeywords.DATATYPE_TEXT; } else if (datatype == DATATYPE.BOOLEAN) { return XLSKeywords.DATATYPE_BOOLEAN; } } } return null; }
PMML pmml = new PMML(); pmml.setVersion("4.0"); header.setTimestamp( ts ); pmml.setHeader( header ); pmml.setDataDictionary(dic); pmml.getAssociationModelsAndBaselineModelsAndClusteringModels().add( nnet );
for (Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels()) {
public DataDictionary getDataDictionary() { if (this.getParentModel() == null) { return this.getOwner().getRawPMML().getDataDictionary(); } return this.getParentModel().getDataDictionary(); }
PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() ); for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) { if ( o instanceof TreeModel ) { TreeModel tree = (TreeModel) o;
pmml.getDataDictionary().getDataFields().add(e); BigInteger bi = pmml.getDataDictionary().getNumberOfFields(); pmml.getDataDictionary().setNumberOfFields(bi.add(BigInteger.ONE)); fieldAdded = true;
@Test public void testMissingTreeDefault() throws Exception { PMML4Compiler compiler = new PMML4Compiler(); PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() ); for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) { if ( o instanceof TreeModel ) { TreeModel tree = (TreeModel) o; tree.setMissingValueStrategy( MISSINGVALUESTRATEGY.DEFAULT_CHILD ); } } KieSession kSession = getSession( compiler.generateTheory( pmml ) ); setKSession( kSession ); setKbase( getKSession().getKieBase() ); kSession.fireAllRules(); //init model FactType tgt = kSession.getKieBase().getFactType( packageName, "Fld9" ); FactType tok = kSession.getKieBase().getFactType( PMML4Helper.pmmlDefaultPackageName(), "TreeToken" ); kSession.getEntryPoint( "in_Fld1" ).insert( 70.0 ); kSession.getEntryPoint( "in_Fld2" ).insert( 40.0 ); kSession.getEntryPoint( "in_Fld3" ).insert( "miss" ); kSession.fireAllRules(); Object token = getToken( kSession ); assertEquals( 0.72, (Double) tok.get( token, "confidence" ), 1e-6 ); assertEquals( "null", tok.get( token, "current" ) ); assertEquals( 40.0, tok.get( token, "totalCount" ) ); checkFirstDataFieldOfTypeStatus(tgt, true, false, "Missing", "tgtX" ); checkGeneratedRules(); }
PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() ); for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) { if ( o instanceof TreeModel ) { TreeModel tree = (TreeModel) o;
PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() ); for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) { if ( o instanceof TreeModel ) { TreeModel tree = (TreeModel) o;
PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() ); for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) { if ( o instanceof TreeModel ) { TreeModel tree = (TreeModel) o;
PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() ); for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) { if ( o instanceof TreeModel ) { TreeModel tree = (TreeModel) o;