Search in sources :

Example 6 with True

use of org.dmg.pmml.True in project pyramid by cheng-li.

the class MiningModelUtil method createSegmentation.

public static Segmentation createSegmentation(Segmentation.MultipleModelMethod multipleModelMethod, List<? extends Model> models, List<? extends Number> weights) {
    if ((weights != null) && (models.size() != weights.size())) {
        throw new IllegalArgumentException();
    }
    List<Segment> segments = new ArrayList<>();
    for (int i = 0; i < models.size(); i++) {
        Model model = models.get(i);
        Number weight = (weights != null ? weights.get(i) : null);
        Segment segment = new Segment().setId(String.valueOf(i + 1)).setPredicate(new True()).setModel(model);
        if (weight != null && !ValueUtil.isOne(weight)) {
            segment.setWeight(ValueUtil.asDouble(weight));
        }
        segments.add(segment);
    }
    return new Segmentation(multipleModelMethod, segments);
}
Also used : Segmentation(org.dmg.pmml.mining.Segmentation) ArrayList(java.util.ArrayList) Model(org.dmg.pmml.Model) MiningModel(org.dmg.pmml.mining.MiningModel) RegressionModel(org.dmg.pmml.regression.RegressionModel) True(org.dmg.pmml.True) Segment(org.dmg.pmml.mining.Segment)

Example 7 with True

use of org.dmg.pmml.True in project shifu by ShifuML.

the class PMMLTranslator method build.

public PMML build(List<BasicML> basicMLs) {
    if (basicMLs == null || basicMLs.size() == 0) {
        throw new IllegalArgumentException("Input ml model list is empty.");
    }
    PMML pmml = new PMML();
    // create and add header
    Header header = new Header();
    pmml.setHeader(header);
    header.setCopyright(" Copyright [2013-2018] PayPal Software Foundation\n" + "\n" + " Licensed under the Apache License, Version 2.0 (the \"License\");\n" + " you may not use this file except in compliance with the License.\n" + " You may obtain a copy of the License at\n" + "\n" + "    http://www.apache.org/licenses/LICENSE-2.0\n" + "\n" + " Unless required by applicable law or agreed to in writing, software\n" + " distributed under the License is distributed on an \"AS IS\" BASIS,\n" + " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + " See the License for the specific language governing permissions and\n" + " limitations under the License.\n");
    Application application = new Application();
    header.setApplication(application);
    application.setName("shifu");
    String findContainingJar = JarManager.findContainingJar(TreeEnsemblePMMLTranslator.class);
    JarFile jar = null;
    try {
        jar = new JarFile(findContainingJar);
        final Manifest manifest = jar.getManifest();
        String version = manifest.getMainAttributes().getValue("version");
        application.setVersion(version);
    } catch (Exception e) {
        LOG.warn(e.getMessage());
    } finally {
        if (jar != null) {
            try {
                jar.close();
            } catch (IOException e) {
                LOG.warn(e.getMessage());
            }
        }
    }
    // create and set data dictionary for all bagging models
    pmml.setDataDictionary(this.dataDictionaryCreator.build(null));
    if (isOutBaggingToOne) {
        MiningModel miningModel = new MiningModel();
        miningModel.setMiningSchema(this.miningSchemaCreator.build(null));
        miningModel.setMiningFunction(MiningFunction.fromValue("regression"));
        miningModel.setTargets(((NNPmmlModelCreator) this.modelCreator).createTargets());
        AbstractSpecifCreator minningModelCreator = new MiningModelPmmlCreator(this.specifCreator.getModelConfig(), this.specifCreator.getColumnConfigList());
        minningModelCreator.build(null, miningModel);
        Segmentation seg = new Segmentation();
        miningModel.setSegmentation(seg);
        seg.setMultipleModelMethod(MultipleModelMethod.AVERAGE);
        List<Segment> list = seg.getSegments();
        int idCount = 0;
        for (BasicML basicML : basicMLs) {
            // create model element
            Model tmpmodel = this.modelCreator.build(basicML);
            // create mining schema
            tmpmodel.setMiningSchema(this.miningSchemaCreator.build(basicML));
            // create variable statistical info
            tmpmodel.setModelStats(this.modelStatsCreator.build(basicML));
            // create variable transform
            tmpmodel.setLocalTransformations(this.localTransformationsCreator.build(basicML));
            this.specifCreator.build(basicML, tmpmodel, idCount);
            Segment segment = new Segment();
            segment.setId("Segement" + String.valueOf(idCount));
            segment.setPredicate(new True());
            segment.setModel(tmpmodel);
            list.add(segment);
            idCount++;
        }
        List<Model> models = pmml.getModels();
        models.add(miningModel);
    } else {
        BasicML basicML = basicMLs.get(0);
        // create model element
        Model model = this.modelCreator.build(basicML);
        // create mining schema
        model.setMiningSchema(this.miningSchemaCreator.build(basicML));
        // create variable statistical info
        model.setModelStats(this.modelStatsCreator.build(basicML));
        // create variable transform
        model.setLocalTransformations(this.localTransformationsCreator.build(basicML));
        this.specifCreator.build(basicML, model);
        pmml.addModels(model);
    }
    return pmml;
}
Also used : Segmentation(org.dmg.pmml.mining.Segmentation) AbstractSpecifCreator(ml.shifu.shifu.core.pmml.builder.creator.AbstractSpecifCreator) True(org.dmg.pmml.True) BasicML(org.encog.ml.BasicML) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) IOException(java.io.IOException) Segment(org.dmg.pmml.mining.Segment) MiningModelPmmlCreator(ml.shifu.shifu.core.pmml.builder.impl.MiningModelPmmlCreator) Header(org.dmg.pmml.Header) MiningModel(org.dmg.pmml.mining.MiningModel) Model(org.dmg.pmml.Model) MiningModel(org.dmg.pmml.mining.MiningModel) PMML(org.dmg.pmml.PMML) Application(org.dmg.pmml.Application)

Example 8 with True

use of org.dmg.pmml.True in project shifu by ShifuML.

the class TreeNodePmmlElementCreator method convert.

public org.dmg.pmml.tree.Node convert(Node node) {
    org.dmg.pmml.tree.Node pmmlNode = new org.dmg.pmml.tree.Node();
    pmmlNode.setId(String.valueOf(node.getId()));
    pmmlNode.setDefaultChild(null);
    pmmlNode.setPredicate(new True());
    pmmlNode.setEmbeddedModel(null);
    List<org.dmg.pmml.tree.Node> childList = pmmlNode.getNodes();
    org.dmg.pmml.tree.Node left = convert(node.getLeft(), true, node.getSplit());
    childList.add(left);
    org.dmg.pmml.tree.Node right = convert(node.getRight(), false, node.getSplit());
    childList.add(right);
    return pmmlNode;
}
Also used : Node(ml.shifu.shifu.core.dtrain.dt.Node) True(org.dmg.pmml.True)

Example 9 with True

use of org.dmg.pmml.True in project drools by kiegroup.

the class KiePMMLTruePredicateASTFactoryTest method declareRuleFromTruePredicateFinalLeaf.

@Test
public void declareRuleFromTruePredicateFinalLeaf() {
    String parentPath = "_will play";
    String currentRule = "_will play_will play";
    final List<KiePMMLDroolsRule> rules = new ArrayList<>();
    String statusToSet = DONE;
    True truePredicate = new True();
    PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(truePredicate, Collections.emptyList(), rules, parentPath, currentRule, Collections.emptyMap());
    KiePMMLTruePredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromTruePredicateWithResult(statusToSet, true);
    assertEquals(1, rules.size());
    final KiePMMLDroolsRule retrieved = rules.get(0);
    assertNotNull(retrieved);
    assertEquals(currentRule, retrieved.getName());
    assertEquals(statusToSet, retrieved.getStatusToSet());
    assertEquals(String.format(STATUS_PATTERN, parentPath), retrieved.getStatusConstraint());
    assertNull(retrieved.getAndConstraints());
    assertEquals(DONE, retrieved.getResult());
    assertEquals(ResultCode.OK, retrieved.getResultCode());
}
Also used : ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) True(org.dmg.pmml.True) KiePMMLASTTestUtils.getPredicateASTFactoryData(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData) Test(org.junit.Test)

Example 10 with True

use of org.dmg.pmml.True in project jpmml-r by jpmml.

the class BinaryTreeConverter method encodeTreeModel.

private TreeModel encodeTreeModel(RGenericVector tree, Schema schema) {
    Node root = new Node().setPredicate(new True());
    encodeNode(root, tree, schema);
    TreeModel treeModel = new TreeModel(this.miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root).setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);
    return treeModel;
}
Also used : TreeModel(org.dmg.pmml.tree.TreeModel) Node(org.dmg.pmml.tree.Node) True(org.dmg.pmml.True)

Aggregations

True (org.dmg.pmml.True)21 Node (org.dmg.pmml.tree.Node)9 TreeModel (org.dmg.pmml.tree.TreeModel)7 SimplePredicate (org.dmg.pmml.SimplePredicate)5 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicate)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 FieldName (org.dmg.pmml.FieldName)3 Predicate (org.dmg.pmml.Predicate)3 MiningModel (org.dmg.pmml.mining.MiningModel)3 Segment (org.dmg.pmml.mining.Segment)3 Segmentation (org.dmg.pmml.mining.Segmentation)3 List (java.util.List)2 Model (org.dmg.pmml.Model)2 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 Statement (com.github.javaparser.ast.stmt.Statement)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1