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