Search in sources :

Example 1 with MiningSegmentation

use of org.kie.pmml.pmml_4_2.model.mining.MiningSegmentation in project drools by kiegroup.

the class PMML4Compiler method addMissingFieldDefinition.

private void addMissingFieldDefinition(PMML pmml, MiningSegmentation msm, MiningSegment seg) {
    // get the list of models that may contain the field definition
    List<PMML4Model> models = msm.getMiningSegments().stream().filter(s -> s != seg && s.getSegmentIndex() < seg.getSegmentIndex()).map(iseg -> {
        return iseg.getModel();
    }).collect(Collectors.toList());
    seg.getModel().getMiningFields().stream().filter(mf -> !mf.isInDictionary()).forEach(pmf -> {
        String fldName = pmf.getName();
        boolean fieldAdded = false;
        for (Iterator<PMML4Model> iter = models.iterator(); iter.hasNext() && !fieldAdded; ) {
            PMML4Model mdl = iter.next();
            PMMLOutputField outfield = mdl.findOutputField(fldName);
            PMMLMiningField target = (outfield != null && outfield.getTargetField() != null) ? mdl.findMiningField(outfield.getTargetField()) : null;
            if (outfield != null) {
                DataField e = null;
                if (outfield.getRawDataField() != null && outfield.getRawDataField().getDataType() != null) {
                    e = outfield.getRawDataField();
                } else if (target != null) {
                    e = target.getRawDataField();
                }
                if (e != null) {
                    e.setName(fldName);
                    pmml.getDataDictionary().getDataFields().add(e);
                    BigInteger bi = pmml.getDataDictionary().getNumberOfFields();
                    pmml.getDataDictionary().setNumberOfFields(bi.add(BigInteger.ONE));
                    fieldAdded = true;
                }
            }
        }
    });
}
Also used : ResourceFactory(org.kie.internal.io.ResourceFactory) SupportVectorMachineModel(org.kie.dmg.pmml.pmml_4_2.descr.SupportVectorMachineModel) Miningmodel(org.kie.pmml.pmml_4_2.model.Miningmodel) TemplateRegistry(org.mvel2.templates.TemplateRegistry) Map(java.util.Map) BigInteger(java.math.BigInteger) Scorecard(org.kie.dmg.pmml.pmml_4_2.descr.Scorecard) KieSession(org.kie.api.runtime.KieSession) TemplateCompiler(org.mvel2.templates.TemplateCompiler) EventProcessingOption(org.kie.api.conf.EventProcessingOption) PMML4UnitImpl(org.kie.pmml.pmml_4_2.model.PMML4UnitImpl) PMMLMiningField(org.kie.pmml.pmml_4_2.model.PMMLMiningField) TreeModel(org.kie.dmg.pmml.pmml_4_2.descr.TreeModel) KnowledgeBuilderResult(org.kie.internal.builder.KnowledgeBuilderResult) KieBaseModel(org.kie.api.builder.model.KieBaseModel) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) Resource(org.kie.api.io.Resource) List(java.util.List) PMMLCompiler(org.drools.compiler.compiler.PMMLCompiler) KieSessionModel(org.kie.api.builder.model.KieSessionModel) SAXException(org.xml.sax.SAXException) Writer(java.io.Writer) NaiveBayesModel(org.kie.dmg.pmml.pmml_4_2.descr.NaiveBayesModel) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) ResourceType(org.kie.api.io.ResourceType) Schema(javax.xml.validation.Schema) ArrayList(java.util.ArrayList) MiningSegmentation(org.kie.pmml.pmml_4_2.model.mining.MiningSegmentation) RegressionModel(org.kie.dmg.pmml.pmml_4_2.descr.RegressionModel) ClusteringModel(org.kie.dmg.pmml.pmml_4_2.descr.ClusteringModel) IoUtils(org.drools.core.util.IoUtils) PMMLResource(org.drools.compiler.compiler.PMMLResource) KieServices(org.kie.api.KieServices) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayResource(org.drools.core.io.impl.ByteArrayResource) XMLConstants(javax.xml.XMLConstants) KieBase(org.kie.api.KieBase) SimpleTemplateRegistry(org.mvel2.templates.SimpleTemplateRegistry) JAXBContext(javax.xml.bind.JAXBContext) MiningSegment(org.kie.pmml.pmml_4_2.model.mining.MiningSegment) OutputStream(java.io.OutputStream) Unmarshaller(javax.xml.bind.Unmarshaller) SchemaFactory(javax.xml.validation.SchemaFactory) Iterator(java.util.Iterator) DataField(org.kie.dmg.pmml.pmml_4_2.descr.DataField) KieContainer(org.kie.api.runtime.KieContainer) IOException(java.io.IOException) DataDictionary(org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary) File(java.io.File) PMMLOutputField(org.kie.pmml.pmml_4_2.model.PMMLOutputField) ClassPathResource(org.drools.core.io.impl.ClassPathResource) KieModuleModel(org.kie.api.builder.model.KieModuleModel) PMML(org.kie.dmg.pmml.pmml_4_2.descr.PMML) Collections(java.util.Collections) InputStream(java.io.InputStream) NeuralNetwork(org.kie.dmg.pmml.pmml_4_2.descr.NeuralNetwork) PMMLOutputField(org.kie.pmml.pmml_4_2.model.PMMLOutputField) DataField(org.kie.dmg.pmml.pmml_4_2.descr.DataField) BigInteger(java.math.BigInteger) PMMLMiningField(org.kie.pmml.pmml_4_2.model.PMMLMiningField)

Example 2 with MiningSegmentation

use of org.kie.pmml.pmml_4_2.model.mining.MiningSegmentation in project drools by kiegroup.

the class Miningmodel method initChildModels.

protected void initChildModels() {
    childModels = new HashMap<>();
    Iterator<Serializable> extenIter = rawModel.getExtensionsAndMiningSchemasAndOutputs().iterator();
    segmentation = null;
    while (extenIter.hasNext() && segmentation == null) {
        Object obj = extenIter.next();
        if (obj instanceof Segmentation) {
            segmentation = new MiningSegmentation(this, (Segmentation) obj);
        }
    }
    if (segmentation != null) {
        List<MiningSegment> segments = segmentation.getMiningSegments();
        DataDictionary dd = this.getDataDictionary();
        for (MiningSegment seg : segmentation.getMiningSegments()) {
            childModels.put(seg.getModel().getModelId(), seg.getModel());
        }
    }
}
Also used : MiningSegmentation(org.kie.pmml.pmml_4_2.model.mining.MiningSegmentation) Serializable(java.io.Serializable) MiningSegmentation(org.kie.pmml.pmml_4_2.model.mining.MiningSegmentation) Segmentation(org.kie.dmg.pmml.pmml_4_2.descr.Segmentation) MiningSegment(org.kie.pmml.pmml_4_2.model.mining.MiningSegment) DataDictionary(org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary)

Example 3 with MiningSegmentation

use of org.kie.pmml.pmml_4_2.model.mining.MiningSegmentation 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

DataDictionary (org.kie.dmg.pmml.pmml_4_2.descr.DataDictionary)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 MiningSegment (org.kie.pmml.pmml_4_2.model.mining.MiningSegment)2 MiningSegmentation (org.kie.pmml.pmml_4_2.model.mining.MiningSegmentation)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Serializable (java.io.Serializable)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Writer (java.io.Writer)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1