Search in sources :

Example 31 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class SimpleRegressionTest method testRegression.

@Test
public void testRegression() throws Exception {
    RuleUnitExecutor executor = createExecutor(source1);
    PMMLRequestData request = new PMMLRequestData("123", "LinReg");
    request.addRequestParam("fld1", 0.9);
    request.addRequestParam("fld2", 0.3);
    request.addRequestParam("fld3", "x");
    PMML4Result resultHolder = new PMML4Result();
    List<String> possiblePackages = calculatePossiblePackageNames("LinReg");
    Class<? extends RuleUnit> unitClass = getStartingRuleUnit("RuleUnitIndicator", (InternalKnowledgeBase) kbase, possiblePackages);
    assertNotNull(unitClass);
    int x = executor.run(unitClass);
    data.insert(request);
    resultData.insert(resultHolder);
    executor.run(unitClass);
    assertEquals("OK", resultHolder.getResultCode());
    assertNotNull(resultHolder.getResultValue("Fld4", null));
    Double value = resultHolder.getResultValue("Fld4", "value", Double.class).orElse(null);
    assertNotNull(value);
    double chkVal = 0.5 + 5 * 0.9 * 0.9 + 2 * 0.3 - 3.0 + 0.4 * 0.9 * 0.3;
    chkVal = 1.0 / (1.0 + Math.exp(-chkVal));
    assertEquals(chkVal, value, 1e-6);
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMML4Result(org.kie.api.pmml.PMML4Result) InternalRuleUnitExecutor(org.drools.core.impl.InternalRuleUnitExecutor) RuleUnitExecutor(org.kie.api.runtime.rule.RuleUnitExecutor) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 32 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class MiningSegmentTransfer method getOutboundRequest.

public PMMLRequestData getOutboundRequest() {
    if (outboundRequest == null) {
        outboundRequest = new PMMLRequestData(this.correlationId);
        outboundRequest.setSource("MiningSegmentTransfer:" + this.fromSegmentId + "-" + this.toSegmentId);
        for (String requestField : requestFromResultMap.keySet()) {
            String resultFieldName = requestFromResultMap.get(requestField);
            Object resultFieldValue = getValueFromResult(resultFieldName);
            if (resultFieldValue != null) {
                outboundRequest.addRequestParam(requestField, resultFieldValue);
            }
        }
    }
    return outboundRequest;
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData)

Aggregations

PMMLRequestData (org.kie.api.pmml.PMMLRequestData)32 Test (org.junit.Test)29 PMML4Result (org.kie.api.pmml.PMML4Result)28 DroolsAbstractPMMLTest (org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)28 InternalRuleUnitExecutor (org.drools.core.impl.InternalRuleUnitExecutor)17 RuleUnitExecutor (org.kie.api.runtime.rule.RuleUnitExecutor)17 KieBase (org.kie.api.KieBase)13 PMMLExecutor (org.kie.pmml.pmml_4_2.PMMLExecutor)11 LinkedHashMap (java.util.LinkedHashMap)6 SegmentExecution (org.kie.pmml.pmml_4_2.model.mining.SegmentExecution)6 Map (java.util.Map)4 AbstractTreeToken (org.kie.pmml.pmml_4_2.model.tree.AbstractTreeToken)4 Iterator (java.util.Iterator)3 Resource (org.kie.api.io.Resource)3 KieRuntimeLogger (org.kie.api.logger.KieRuntimeLogger)3 PMML4Data (org.kie.api.pmml.PMML4Data)3 KieHelper (org.kie.internal.utils.KieHelper)3 ScoreCard (org.kie.pmml.pmml_4_2.model.ScoreCard)2 FactType (org.kie.api.definition.type.FactType)1 ParameterInfo (org.kie.api.pmml.ParameterInfo)1