Search in sources :

Example 1 with NumericPredictor

use of org.dmg.pmml.regression.NumericPredictor in project drools by kiegroup.

the class KiePMMLRegressionModelFactoryTest method evaluateRegressionTable.

private void evaluateRegressionTable(KiePMMLRegressionTable regressionTable, RegressionTable originalRegressionTable) {
    assertEquals(originalRegressionTable.getIntercept(), regressionTable.getIntercept());
    final Map<String, SerializableFunction<Double, Double>> numericFunctionMap = regressionTable.getNumericFunctionMap();
    for (NumericPredictor numericPredictor : originalRegressionTable.getNumericPredictors()) {
        assertTrue(numericFunctionMap.containsKey(numericPredictor.getName().getValue()));
    }
    final Map<String, SerializableFunction<String, Double>> categoricalFunctionMap = regressionTable.getCategoricalFunctionMap();
    for (CategoricalPredictor categoricalPredictor : originalRegressionTable.getCategoricalPredictors()) {
        assertTrue(categoricalFunctionMap.containsKey(categoricalPredictor.getName().getValue()));
    }
    final Map<String, SerializableFunction<Map<String, Object>, Double>> predictorTermsFunctionMap = regressionTable.getPredictorTermsFunctionMap();
    for (PredictorTerm predictorTerm : originalRegressionTable.getPredictorTerms()) {
        assertTrue(predictorTermsFunctionMap.containsKey(predictorTerm.getName().getValue()));
    }
}
Also used : CategoricalPredictor(org.dmg.pmml.regression.CategoricalPredictor) PMMLModelTestUtils.getCategoricalPredictor(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getCategoricalPredictor) PredictorTerm(org.dmg.pmml.regression.PredictorTerm) PMMLModelTestUtils.getPredictorTerm(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getPredictorTerm) SerializableFunction(org.kie.pmml.api.iinterfaces.SerializableFunction) NumericPredictor(org.dmg.pmml.regression.NumericPredictor) PMMLModelTestUtils.getNumericPredictor(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getNumericPredictor)

Example 2 with NumericPredictor

use of org.dmg.pmml.regression.NumericPredictor in project drools by kiegroup.

the class KiePMMLRegressionTableFactoryTest method getNumericPredictorEntryWithExponent.

@Test
public void getNumericPredictorEntryWithExponent() {
    String predictorName = "predictorName";
    int exponent = 2;
    double coefficient = 1.23;
    NumericPredictor numericPredictor = PMMLModelTestUtils.getNumericPredictor(predictorName, exponent, coefficient);
    SerializableFunction<Double, Double> retrieved = KiePMMLRegressionTableFactory.getNumericPredictorEntry(numericPredictor);
    assertNotNull(retrieved);
}
Also used : NumericPredictor(org.dmg.pmml.regression.NumericPredictor) Test(org.junit.Test)

Example 3 with NumericPredictor

use of org.dmg.pmml.regression.NumericPredictor in project drools by kiegroup.

the class KiePMMLRegressionTableFactoryTest method getNumericPredictorEntryWithoutExponent.

@Test
public void getNumericPredictorEntryWithoutExponent() {
    String predictorName = "predictorName";
    int exponent = 1;
    double coefficient = 1.23;
    NumericPredictor numericPredictor = PMMLModelTestUtils.getNumericPredictor(predictorName, exponent, coefficient);
    SerializableFunction<Double, Double> retrieved = KiePMMLRegressionTableFactory.getNumericPredictorEntry(numericPredictor);
    assertNotNull(retrieved);
}
Also used : NumericPredictor(org.dmg.pmml.regression.NumericPredictor) Test(org.junit.Test)

Example 4 with NumericPredictor

use of org.dmg.pmml.regression.NumericPredictor in project drools by kiegroup.

the class KiePMMLRegressionTableFactoryTest method getNumericPredictorExpressionWithoutExponent.

@Test
public void getNumericPredictorExpressionWithoutExponent() throws IOException {
    String predictorName = "predictorName";
    int exponent = 1;
    double coefficient = 1.23;
    NumericPredictor numericPredictor = PMMLModelTestUtils.getNumericPredictor(predictorName, exponent, coefficient);
    CastExpr retrieved = KiePMMLRegressionTableFactory.getNumericPredictorExpression(numericPredictor);
    String text = getFileContent(TEST_02_SOURCE);
    Expression expected = JavaParserUtils.parseExpression(String.format(text, coefficient));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
}
Also used : Expression(com.github.javaparser.ast.expr.Expression) CastExpr(com.github.javaparser.ast.expr.CastExpr) NumericPredictor(org.dmg.pmml.regression.NumericPredictor) Test(org.junit.Test)

Example 5 with NumericPredictor

use of org.dmg.pmml.regression.NumericPredictor in project drools by kiegroup.

the class PMMLModelTestUtils method getNumericPredictor.

public static NumericPredictor getNumericPredictor(String name, int exponent, double coefficient) {
    NumericPredictor toReturn = new NumericPredictor();
    toReturn.setField(FieldName.create(name));
    toReturn.setExponent(exponent);
    toReturn.setCoefficient(coefficient);
    return toReturn;
}
Also used : NumericPredictor(org.dmg.pmml.regression.NumericPredictor)

Aggregations

NumericPredictor (org.dmg.pmml.regression.NumericPredictor)10 Test (org.junit.Test)4 CategoricalPredictor (org.dmg.pmml.regression.CategoricalPredictor)3 PredictorTerm (org.dmg.pmml.regression.PredictorTerm)3 RegressionTable (org.dmg.pmml.regression.RegressionTable)3 CastExpr (com.github.javaparser.ast.expr.CastExpr)2 Expression (com.github.javaparser.ast.expr.Expression)2 DerivedField (org.dmg.pmml.DerivedField)2 FieldName (org.dmg.pmml.FieldName)2 NormContinuous (org.dmg.pmml.NormContinuous)2 PMMLModelTestUtils.getCategoricalPredictor (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getCategoricalPredictor)2 PMMLModelTestUtils.getNumericPredictor (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getNumericPredictor)2 PMMLModelTestUtils.getPredictorTerm (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getPredictorTerm)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 Discretize (org.dmg.pmml.Discretize)1 Expression (org.dmg.pmml.Expression)1 LocalTransformations (org.dmg.pmml.LocalTransformations)1