Search in sources :

Example 11 with Interval

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

the class PMMLModelTestUtils method getRandomDiscretizeBin.

public static DiscretizeBin getRandomDiscretizeBin() {
    Interval interval = getRandomInterval();
    DiscretizeBin toReturn = new DiscretizeBin();
    toReturn.setInterval(interval);
    toReturn.setBinValue(RandomStringUtils.random(6, true, false));
    return toReturn;
}
Also used : DiscretizeBin(org.dmg.pmml.DiscretizeBin) Interval(org.dmg.pmml.Interval)

Example 12 with Interval

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

the class WoeLocalTransformCreator 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
 */
@Override
protected List<DerivedField> createNumericalDerivedField(ColumnConfig config, double cutoff, ModelNormalizeConf.NormType normType) {
    List<Double> binWoeList = (normType.equals(ModelNormalizeConf.NormType.WOE) ? config.getBinCountWoe() : config.getBinWeightedWoe());
    List<Double> binBoundaryList = config.getBinBoundary();
    List<DiscretizeBin> discretizeBinList = new ArrayList<DiscretizeBin>();
    for (int i = 0; i < binBoundaryList.size(); i++) {
        DiscretizeBin discretizeBin = new DiscretizeBin();
        Interval interval = new Interval();
        if (i == 0) {
            if (binBoundaryList.size() == 1) {
                interval.setClosure(Interval.Closure.OPEN_OPEN).setLeftMargin(Double.NEGATIVE_INFINITY).setRightMargin(Double.POSITIVE_INFINITY);
            } else {
                interval.setClosure(Interval.Closure.OPEN_OPEN).setRightMargin(binBoundaryList.get(i + 1));
            }
        } else if (i == binBoundaryList.size() - 1) {
            interval.setClosure(Interval.Closure.CLOSED_OPEN).setLeftMargin(binBoundaryList.get(i));
        } else {
            interval.setClosure(Interval.Closure.CLOSED_OPEN).setLeftMargin(binBoundaryList.get(i)).setRightMargin(binBoundaryList.get(i + 1));
        }
        discretizeBin.setInterval(interval).setBinValue(Double.toString(binWoeList.get(i)));
        discretizeBinList.add(discretizeBin);
    }
    Discretize discretize = new Discretize();
    discretize.setDataType(DataType.DOUBLE).setField(FieldName.create(NormalUtils.getSimpleColumnName(config, columnConfigList, segmentExpansions, datasetHeaders))).setMapMissingTo(Normalizer.normalize(config, null, cutoff, normType).get(0).toString()).setDefaultValue(Normalizer.normalize(config, null, cutoff, normType).get(0).toString()).addDiscretizeBins(discretizeBinList.toArray(new DiscretizeBin[discretizeBinList.size()]));
    // 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(discretize));
    return derivedFields;
}
Also used : ArrayList(java.util.ArrayList) Discretize(org.dmg.pmml.Discretize) DiscretizeBin(org.dmg.pmml.DiscretizeBin) DerivedField(org.dmg.pmml.DerivedField) Interval(org.dmg.pmml.Interval)

Example 13 with Interval

use of org.dmg.pmml.Interval in project jpmml-r by jpmml.

the class FormulaUtil method createDiscretize.

private static Discretize createDiscretize(String name, List<String> categories) {
    Discretize discretize = new Discretize(name);
    for (String category : categories) {
        Interval interval = ExpressionTranslator.translateInterval(category);
        DiscretizeBin discretizeBin = new DiscretizeBin(category, interval);
        discretize.addDiscretizeBins(discretizeBin);
    }
    return discretize;
}
Also used : Discretize(org.dmg.pmml.Discretize) DiscretizeBin(org.dmg.pmml.DiscretizeBin) Interval(org.dmg.pmml.Interval)

Example 14 with Interval

use of org.dmg.pmml.Interval in project jpmml-r by jpmml.

the class ExpressionTranslatorTest method translateInterval.

@Test
public void translateInterval() {
    Interval expected = new Interval(Interval.Closure.OPEN_CLOSED).setLeftMargin(new Double("-10.0E0")).setRightMargin(new Double("+10.0E0"));
    Interval actual = ExpressionTranslator.translateInterval("(-10.0E+0, +10.0E-0]");
    assertTrue(ReflectionUtil.equals(expected, actual));
    try {
        ExpressionTranslator.translateInterval("(0, NaN)");
        fail();
    } catch (IllegalArgumentException iae) {
    // Ignored
    }
    expected = new Interval(Interval.Closure.CLOSED_CLOSED).setLeftMargin(null).setRightMargin(null);
    actual = ExpressionTranslator.translateInterval("[-Inf, +Inf]");
    assertTrue(ReflectionUtil.equals(expected, actual));
}
Also used : Interval(org.dmg.pmml.Interval) Test(org.junit.Test)

Aggregations

Interval (org.dmg.pmml.Interval)14 DiscretizeBin (org.dmg.pmml.DiscretizeBin)6 ArrayList (java.util.ArrayList)5 Discretize (org.dmg.pmml.Discretize)4 Test (org.junit.Test)4 KiePMMLInterval (org.kie.pmml.commons.model.expressions.KiePMMLInterval)4 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)2 Statement (com.github.javaparser.ast.stmt.Statement)2 HashMap (java.util.HashMap)2 DerivedField (org.dmg.pmml.DerivedField)2 Value (org.dmg.pmml.Value)2 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 Bucketizer (org.apache.spark.ml.feature.Bucketizer)1 ContStats (org.dmg.pmml.ContStats)1