Search in sources :

Example 1 with MiningModel

use of org.kie.dmg.pmml.pmml_4_2.descr.MiningModel in project drools by kiegroup.

the class PMML4ModelFactory method getModels.

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;
}
Also used : TreeModel(org.kie.dmg.pmml.pmml_4_2.descr.TreeModel) MiningModel(org.kie.dmg.pmml.pmml_4_2.descr.MiningModel) PMML4Model(org.kie.pmml.pmml_4_2.PMML4Model) ArrayList(java.util.ArrayList) Scorecard(org.kie.dmg.pmml.pmml_4_2.descr.Scorecard) RegressionModel(org.kie.dmg.pmml.pmml_4_2.descr.RegressionModel)

Example 2 with MiningModel

use of org.kie.dmg.pmml.pmml_4_2.descr.MiningModel in project drools by kiegroup.

the class PMML4Compiler method precompile.

public List<PMMLResource> precompile(InputStream stream, ClassLoader classLoader, KieBaseModel rootKieBaseModel) {
    List<PMMLResource> resources = new ArrayList<>();
    KieServices services = KieServices.Factory.get();
    KieModuleModel module = services.newKieModuleModel();
    this.results = new ArrayList<KnowledgeBuilderResult>();
    PMML pmml = loadModel(PMML, stream);
    helper.setResolver(classLoader);
    PMML4Unit unit = new PMML4UnitImpl(pmml);
    if (unit.containsMiningModel()) {
        Miningmodel rootModel = unit.getRootMiningModel();
        resources = buildResourcesFromModel(pmml, rootModel, null, classLoader, module);
    } else {
        PMML4Model rootModel = unit.getRootModel();
        if (rootModel != null) {
            helper.setPack(rootModel.getModelPackageName());
            KieBaseModel kbm = module.newKieBaseModel(rootModel.getModelId());
            kbm.addPackage(helper.getPack()).setDefault(true).setEventProcessingMode(EventProcessingOption.CLOUD);
            PMMLResource resource = new PMMLResource(helper.getPack());
            resource.setKieBaseModel(kbm);
            resource.addRules(rootModel.getModelId(), this.compile(pmml, classLoader));
            resources.add(resource);
        }
    }
    return resources;
}
Also used : ArrayList(java.util.ArrayList) Miningmodel(org.kie.pmml.pmml_4_2.model.Miningmodel) KieServices(org.kie.api.KieServices) PMMLResource(org.drools.compiler.compiler.PMMLResource) KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) PMML(org.kie.dmg.pmml.pmml_4_2.descr.PMML) PMML4UnitImpl(org.kie.pmml.pmml_4_2.model.PMML4UnitImpl) KnowledgeBuilderResult(org.kie.internal.builder.KnowledgeBuilderResult)

Example 3 with MiningModel

use of org.kie.dmg.pmml.pmml_4_2.descr.MiningModel in project drools by kiegroup.

the class AbstractModel method getMiningFields.

@Override
public List<PMMLMiningField> getMiningFields() {
    List<PMMLMiningField> fields = new ArrayList<>();
    Map<String, MiningField> excludesTargetMap = getFilteredMiningFieldMap(false, FIELDUSAGETYPE.TARGET);
    Map<String, PMMLDataField> dataDictionary = getOwner().getDataDictionaryMap();
    for (String key : excludesTargetMap.keySet()) {
        PMMLDataField df = dataDictionary.get(key);
        MiningField mf = miningFieldMap.get(key);
        if (df != null) {
            fields.add(new PMMLMiningField(mf, df.getRawDataField(), this.getModelId(), true));
        } else {
            PMMLMiningField fld = new PMMLMiningField(mf, this.getModelId());
            if (this.getParentModel() != null) {
                PMML4Model ultimateParentModel = this.getParentModel();
                if (ultimateParentModel instanceof Miningmodel) {
                    while (ultimateParentModel.getParentModel() != null) {
                        ultimateParentModel = ultimateParentModel.getParentModel();
                    }
                    PMMLOutputField ofld = ((Miningmodel) ultimateParentModel).findOutputField(fld.getName());
                    if (ofld != null) {
                        fld.setType(ofld.getType());
                        fields.add(fld);
                    }
                }
            }
        }
    }
    return fields;
}
Also used : MiningField(org.kie.dmg.pmml.pmml_4_2.descr.MiningField) ArrayList(java.util.ArrayList) PMML4Model(org.kie.pmml.pmml_4_2.PMML4Model)

Example 4 with MiningModel

use of org.kie.dmg.pmml.pmml_4_2.descr.MiningModel in project drools by kiegroup.

the class PMML4ModelFactory method getModel.

public PMML4Model getModel(Segment segment, MiningSegmentation segmentation) {
    PMML4Model model = null;
    if (segment.getMiningModel() != null) {
        MiningModel mm = segment.getMiningModel();
        model = new Miningmodel(mm.getModelName(), mm, segmentation.getOwner(), null);
    } else if (segment.getRegressionModel() != null) {
        RegressionModel rm = segment.getRegressionModel();
        model = new Regression(rm.getModelName(), rm, segmentation.getOwner(), null);
    } else if (segment.getScorecard() != null) {
        Scorecard sc = segment.getScorecard();
        model = new ScorecardModel(sc.getModelName(), sc, segmentation.getOwner(), null);
    } else if (segment.getTreeModel() != null) {
        TreeModel tm = segment.getTreeModel();
        model = new Treemodel(tm.getModelName(), tm, segmentation.getOwner(), null);
    }
    return model;
}
Also used : TreeModel(org.kie.dmg.pmml.pmml_4_2.descr.TreeModel) MiningModel(org.kie.dmg.pmml.pmml_4_2.descr.MiningModel) PMML4Model(org.kie.pmml.pmml_4_2.PMML4Model) Scorecard(org.kie.dmg.pmml.pmml_4_2.descr.Scorecard) RegressionModel(org.kie.dmg.pmml.pmml_4_2.descr.RegressionModel)

Aggregations

ArrayList (java.util.ArrayList)3 PMML4Model (org.kie.pmml.pmml_4_2.PMML4Model)3 MiningModel (org.kie.dmg.pmml.pmml_4_2.descr.MiningModel)2 RegressionModel (org.kie.dmg.pmml.pmml_4_2.descr.RegressionModel)2 Scorecard (org.kie.dmg.pmml.pmml_4_2.descr.Scorecard)2 TreeModel (org.kie.dmg.pmml.pmml_4_2.descr.TreeModel)2 PMMLResource (org.drools.compiler.compiler.PMMLResource)1 KieServices (org.kie.api.KieServices)1 KieBaseModel (org.kie.api.builder.model.KieBaseModel)1 KieModuleModel (org.kie.api.builder.model.KieModuleModel)1 MiningField (org.kie.dmg.pmml.pmml_4_2.descr.MiningField)1 PMML (org.kie.dmg.pmml.pmml_4_2.descr.PMML)1 KnowledgeBuilderResult (org.kie.internal.builder.KnowledgeBuilderResult)1 Miningmodel (org.kie.pmml.pmml_4_2.model.Miningmodel)1 PMML4UnitImpl (org.kie.pmml.pmml_4_2.model.PMML4UnitImpl)1