Search in sources :

Example 1 with NormContinuous

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

the class WoeZscoreLocalTransformCreator method createNumericalDerivedField.

/**
 * Create @DerivedField for numerical variable
 *
 * @param config - ColumnConfig for numerical variable
 * @param cutoff - cutoff of normalization
 * @return DerivedField for variable
 */
@Override
protected List<DerivedField> createNumericalDerivedField(ColumnConfig config, double cutoff, ModelNormalizeConf.NormType normType) {
    List<DerivedField> derivedFields = new ArrayList<DerivedField>();
    DerivedField derivedField = super.createNumericalDerivedField(config, cutoff, ModelNormalizeConf.NormType.WOE).get(0);
    derivedFields.add(derivedField);
    double[] meanAndStdDev = Normalizer.calculateWoeMeanAndStdDev(config, isWeightedNorm);
    // added capping logic to linearNorm
    LinearNorm from = new LinearNorm().setOrig(meanAndStdDev[0] - meanAndStdDev[1] * cutoff).setNorm(-cutoff);
    LinearNorm to = new LinearNorm().setOrig(meanAndStdDev[0] + meanAndStdDev[1] * cutoff).setNorm(cutoff);
    NormContinuous normContinuous = new NormContinuous();
    normContinuous.setField(FieldName.create(derivedField.getName().getValue()));
    normContinuous.addLinearNorms(from, to);
    normContinuous.setMapMissingTo(0.0);
    normContinuous.setOutliers(OutlierTreatmentMethod.AS_EXTREME_VALUES);
    // derived field name is consisted of FieldName and "_zscl"
    derivedFields.add(new DerivedField(OpType.CONTINUOUS, DataType.DOUBLE).setName(FieldName.create(genPmmlColumnName(NormalUtils.getSimpleColumnName(config.getColumnName()), normType))).setExpression(normContinuous));
    return derivedFields;
}
Also used : NormContinuous(org.dmg.pmml.NormContinuous) LinearNorm(org.dmg.pmml.LinearNorm) ArrayList(java.util.ArrayList) DerivedField(org.dmg.pmml.DerivedField)

Example 2 with NormContinuous

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

the class ZscoreLocalTransformCreator method createNumericalDerivedField.

/**
 * Create @DerivedField for numerical variable
 *
 * @param config
 *            - ColumnConfig for numerical variable
 * @param cutoff
 *            - cutoff of normalization
 * @param normType
 *            - the normalization method that is used to generate DerivedField
 * @return DerivedField for variable
 */
protected List<DerivedField> createNumericalDerivedField(ColumnConfig config, double cutoff, ModelNormalizeConf.NormType normType) {
    // added capping logic to linearNorm
    LinearNorm from = new LinearNorm().setOrig(config.getMean() - config.getStdDev() * cutoff).setNorm(-cutoff);
    LinearNorm to = new LinearNorm().setOrig(config.getMean() + config.getStdDev() * cutoff).setNorm(cutoff);
    NormContinuous normContinuous = new NormContinuous();
    normContinuous.setField(FieldName.create(NormalUtils.getSimpleColumnName(config, columnConfigList, segmentExpansions, datasetHeaders)));
    normContinuous.addLinearNorms(from, to);
    normContinuous.setMapMissingTo(0.0);
    normContinuous.setOutliers(OutlierTreatmentMethod.AS_EXTREME_VALUES);
    // derived field name is consisted of FieldName and "_zscl"
    List<DerivedField> derivedFields = new ArrayList<DerivedField>();
    derivedFields.add(new DerivedField(OpType.CONTINUOUS, DataType.DOUBLE).setName(FieldName.create(genPmmlColumnName(NormalUtils.getSimpleColumnName(config.getColumnName()), normType))).setExpression(normContinuous));
    return derivedFields;
}
Also used : NormContinuous(org.dmg.pmml.NormContinuous) LinearNorm(org.dmg.pmml.LinearNorm) ArrayList(java.util.ArrayList) DerivedField(org.dmg.pmml.DerivedField)

Example 3 with NormContinuous

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

the class PMMLModelTestUtils method getRandomNormContinuous.

public static NormContinuous getRandomNormContinuous() {
    Random random = new Random();
    double mapMissingTo = random.nextInt(100) / 10;
    NormContinuous toReturn = new NormContinuous();
    IntStream.range(0, 3).forEach(i -> toReturn.addLinearNorms(getRandomLinearNorm()));
    toReturn.setField(FieldName.create(RandomStringUtils.random(6, true, false)));
    toReturn.setOutliers(getRandomOutlierTreatmentMethod());
    toReturn.setMapMissingTo(mapMissingTo);
    return toReturn;
}
Also used : NormContinuous(org.dmg.pmml.NormContinuous) Random(java.util.Random)

Example 4 with NormContinuous

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

the class KiePMMLNormContinuousInstanceFactoryTest method getKiePMMLNormContinuous.

@Test
public void getKiePMMLNormContinuous() {
    final NormContinuous toConvert = getRandomNormContinuous();
    final KiePMMLNormContinuous retrieved = KiePMMLNormContinuousInstanceFactory.getKiePMMLNormContinuous(toConvert);
    commonVerifyKiePMMLNormContinuous(retrieved, toConvert);
}
Also used : KiePMMLNormContinuous(org.kie.pmml.commons.model.expressions.KiePMMLNormContinuous) InstanceFactoriesTestCommon.commonVerifyKiePMMLNormContinuous(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLNormContinuous) PMMLModelTestUtils.getRandomNormContinuous(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomNormContinuous) NormContinuous(org.dmg.pmml.NormContinuous) KiePMMLNormContinuous(org.kie.pmml.commons.model.expressions.KiePMMLNormContinuous) InstanceFactoriesTestCommon.commonVerifyKiePMMLNormContinuous(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLNormContinuous) Test(org.junit.Test)

Example 5 with NormContinuous

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

the class KiePMMLNormContinuousFactoryTest method getNormContinuousVariableDeclaration.

@Test
public void getNormContinuousVariableDeclaration() throws IOException {
    String variableName = "variableName";
    NormContinuous normContinuous = getRandomNormContinuous();
    List<LinearNorm> linearNorms = normContinuous.getLinearNorms();
    BlockStmt retrieved = KiePMMLNormContinuousFactory.getNormContinuousVariableDeclaration(variableName, normContinuous);
    String outlierString = OUTLIER_TREATMENT_METHOD.class.getName() + "." + OUTLIER_TREATMENT_METHOD.byName(normContinuous.getOutliers().value()).name();
    String text = getFileContent(TEST_01_SOURCE);
    Statement expected = JavaParserUtils.parseBlock(String.format(text, variableName, normContinuous.getField().getValue(), linearNorms.get(0).getOrig(), linearNorms.get(0).getNorm(), linearNorms.get(1).getOrig(), linearNorms.get(1).getNorm(), linearNorms.get(2).getOrig(), linearNorms.get(2).getNorm(), outlierString, normContinuous.getMapMissingTo()));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLLinearNorm.class, KiePMMLNormContinuous.class, OUTLIER_TREATMENT_METHOD.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : PMMLModelTestUtils.getRandomNormContinuous(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomNormContinuous) NormContinuous(org.dmg.pmml.NormContinuous) KiePMMLNormContinuous(org.kie.pmml.commons.model.expressions.KiePMMLNormContinuous) PMMLModelTestUtils.getRandomLinearNorm(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomLinearNorm) KiePMMLLinearNorm(org.kie.pmml.commons.model.expressions.KiePMMLLinearNorm) LinearNorm(org.dmg.pmml.LinearNorm) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) Test(org.junit.Test)

Aggregations

NormContinuous (org.dmg.pmml.NormContinuous)9 DerivedField (org.dmg.pmml.DerivedField)6 ArrayList (java.util.ArrayList)4 LinearNorm (org.dmg.pmml.LinearNorm)4 FieldName (org.dmg.pmml.FieldName)3 HashMap (java.util.HashMap)2 Discretize (org.dmg.pmml.Discretize)2 MapValues (org.dmg.pmml.MapValues)2 MiningField (org.dmg.pmml.MiningField)2 NumericPredictor (org.dmg.pmml.regression.NumericPredictor)2 RegressionTable (org.dmg.pmml.regression.RegressionTable)2 Test (org.junit.Test)2 KiePMMLNormContinuous (org.kie.pmml.commons.model.expressions.KiePMMLNormContinuous)2 PMMLModelTestUtils.getRandomNormContinuous (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomNormContinuous)2 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 Statement (com.github.javaparser.ast.stmt.Statement)1 List (java.util.List)1 Random (java.util.Random)1 Expression (org.dmg.pmml.Expression)1 FieldRef (org.dmg.pmml.FieldRef)1