Search in sources :

Example 31 with DerivedField

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

the class KiePMMLTransformationDictionaryFactory method addDerivedField.

static NodeList<Expression> addDerivedField(final BlockStmt body, final List<DerivedField> derivedFields) {
    NodeList<Expression> arguments = new NodeList<>();
    int counter = 0;
    for (DerivedField derivedField : derivedFields) {
        String nestedVariableName = String.format("transformationDictionaryDerivedField_%s", counter);
        arguments.add(new NameExpr(nestedVariableName));
        BlockStmt toAdd = getDerivedFieldVariableDeclaration(nestedVariableName, derivedField);
        toAdd.getStatements().forEach(body::addStatement);
        counter++;
    }
    return getArraysAsListInvocation(arguments);
}
Also used : Expression(com.github.javaparser.ast.expr.Expression) NodeList(com.github.javaparser.ast.NodeList) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) DerivedField(org.dmg.pmml.DerivedField)

Example 32 with DerivedField

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

the class KiePMMLDerivedFieldASTFactoryTest method declareType.

@Test
public void declareType() {
    DerivedField derivedField = getDerivedField("FieldName");
    KiePMMLDroolsType retrieved = fieldASTFactory.declareType(derivedField);
    commonValidateKiePMMLDroolsType(retrieved, derivedField);
}
Also used : KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) DerivedField(org.dmg.pmml.DerivedField) Test(org.junit.Test)

Example 33 with DerivedField

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

the class KiePMMLDerivedFieldASTFactoryTest method getDerivedField.

private DerivedField getDerivedField(String fieldName) {
    DerivedField toReturn = new DerivedField();
    toReturn.setName(FieldName.create(fieldName));
    final DATA_TYPE[] values = DATA_TYPE.values();
    int rndInt = new Random().nextInt(values.length - 1);
    DATA_TYPE dataType = values[rndInt];
    toReturn.setDataType(DataType.fromValue(dataType.getName()));
    return toReturn;
}
Also used : Random(java.util.Random) DerivedField(org.dmg.pmml.DerivedField) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE)

Example 34 with DerivedField

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

the class PMMLModelTestUtils method getDerivedField.

public static DerivedField getDerivedField(String fieldName) {
    DerivedField toReturn = new DerivedField();
    toReturn.setName(FieldName.create(fieldName));
    toReturn.setDataType(getRandomDataType());
    toReturn.setOpType(getRandomOpType());
    Constant expression = new Constant(5);
    expression.setDataType(DataType.INTEGER);
    toReturn.setExpression(expression);
    toReturn.setDisplayName("Display-" + fieldName);
    return toReturn;
}
Also used : Constant(org.dmg.pmml.Constant) DerivedField(org.dmg.pmml.DerivedField)

Example 35 with DerivedField

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

the class PMMLAdapterCommonUtil method getRegressionTable.

/**
 * Generate Regression Table based on the weight list, intercept and partial
 * PMML model
 *
 * @param weights
 *            weight list for the Regression Table
 * @param intercept
 *            the intercept
 * @param pmmlModel
 *            partial PMMl model
 * @return regression model instance
 */
public static RegressionModel getRegressionTable(final double[] weights, final double intercept, RegressionModel pmmlModel) {
    RegressionTable table = new RegressionTable();
    MiningSchema schema = pmmlModel.getMiningSchema();
    // TODO may not need target field in LRModel
    pmmlModel.setMiningFunction(MiningFunction.REGRESSION);
    pmmlModel.setNormalizationMethod(NormalizationMethod.LOGIT);
    List<String> outputFields = getSchemaFieldViaUsageType(schema, UsageType.TARGET);
    // TODO only one outputField, what if we have more than one outputField
    pmmlModel.setTargetFieldName(new FieldName(outputFields.get(0)));
    table.setTargetCategory(outputFields.get(0));
    List<String> activeFields = getSchemaFieldViaUsageType(schema, UsageType.ACTIVE);
    int index = 0;
    for (DerivedField dField : pmmlModel.getLocalTransformations().getDerivedFields()) {
        Expression expression = dField.getExpression();
        if (expression instanceof NormContinuous) {
            NormContinuous norm = (NormContinuous) expression;
            if (activeFields.contains(norm.getField().getValue()))
                table.addNumericPredictors(new NumericPredictor(dField.getName(), weights[index++]));
        }
    }
    pmmlModel.addRegressionTables(table);
    return pmmlModel;
}
Also used : NormContinuous(org.dmg.pmml.NormContinuous) MiningSchema(org.dmg.pmml.MiningSchema) Expression(org.dmg.pmml.Expression) FieldName(org.dmg.pmml.FieldName) DerivedField(org.dmg.pmml.DerivedField) NumericPredictor(org.dmg.pmml.regression.NumericPredictor) RegressionTable(org.dmg.pmml.regression.RegressionTable)

Aggregations

DerivedField (org.dmg.pmml.DerivedField)48 ArrayList (java.util.ArrayList)17 ContinuousFeature (org.jpmml.converter.ContinuousFeature)16 Feature (org.jpmml.converter.Feature)16 Apply (org.dmg.pmml.Apply)10 Expression (org.dmg.pmml.Expression)10 FieldName (org.dmg.pmml.FieldName)9 Test (org.junit.Test)8 KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)8 Constant (org.dmg.pmml.Constant)7 DataField (org.dmg.pmml.DataField)7 NormContinuous (org.dmg.pmml.NormContinuous)6 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)5 List (java.util.List)5 CategoricalFeature (org.jpmml.converter.CategoricalFeature)5 Discretize (org.dmg.pmml.Discretize)4 FieldRef (org.dmg.pmml.FieldRef)4 MapValues (org.dmg.pmml.MapValues)4 Statement (com.github.javaparser.ast.stmt.Statement)3 HashMap (java.util.HashMap)3