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;
}
}
}
});
}
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());
}
}
}
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;
}
Aggregations