Search in sources :

Example 1 with Interval

use of org.dmg.pmml.Interval in project openscoring by openscoring.

the class ModelUtil method encodeValues.

private static List<String> encodeValues(DataField dataField) {
    List<String> result = new ArrayList<>();
    List<Interval> intervals = dataField.getIntervals();
    for (Interval interval : intervals) {
        StringBuilder sb = new StringBuilder();
        Double leftMargin = interval.getLeftMargin();
        sb.append(Double.toString(leftMargin != null ? leftMargin : Double.NEGATIVE_INFINITY));
        sb.append(", ");
        Double rightMargin = interval.getRightMargin();
        sb.append(Double.toString(rightMargin != null ? rightMargin : Double.POSITIVE_INFINITY));
        String value = sb.toString();
        Interval.Closure closure = interval.getClosure();
        switch(closure) {
            case OPEN_OPEN:
                result.add("(" + value + ")");
                break;
            case OPEN_CLOSED:
                result.add("(" + value + "]");
                break;
            case CLOSED_OPEN:
                result.add("[" + value + ")");
                break;
            case CLOSED_CLOSED:
                result.add("[" + value + "]");
                break;
            default:
                break;
        }
    }
    List<Value> values = dataField.getValues();
    for (Value value : values) {
        Value.Property property = value.getProperty();
        switch(property) {
            case VALID:
                result.add(value.getValue());
                break;
            default:
                break;
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Value(org.dmg.pmml.Value) Interval(org.dmg.pmml.Interval)

Example 2 with Interval

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

the class ModelStatsCreator method createConStats.

/**
 * Create @ConStats for numerical variable
 *
 * @param columnConfig
 *            - ColumnConfig to generate ConStats
 * @return ConStats for variable
 */
private ContStats createConStats(ColumnConfig columnConfig) {
    ContStats conStats = new ContStats();
    List<Interval> intervals = new ArrayList<Interval>();
    for (int i = 0; i < columnConfig.getBinBoundary().size(); i++) {
        Interval interval = new Interval();
        interval.setClosure(Interval.Closure.OPEN_CLOSED);
        interval.setLeftMargin(columnConfig.getBinBoundary().get(i));
        if (i == columnConfig.getBinBoundary().size() - 1) {
            interval.setRightMargin(Double.POSITIVE_INFINITY);
        } else {
            interval.setRightMargin(columnConfig.getBinBoundary().get(i + 1));
        }
        intervals.add(interval);
    }
    conStats.addIntervals(intervals.toArray(new Interval[intervals.size()]));
    Map<String, String> extensionMap = new HashMap<String, String>();
    extensionMap.put("BinCountPos", columnConfig.getBinCountPos().toString());
    extensionMap.put("BinCountNeg", columnConfig.getBinCountNeg().toString());
    extensionMap.put("BinWeightedCountPos", columnConfig.getBinWeightedPos().toString());
    extensionMap.put("BinWeightedCountNeg", columnConfig.getBinWeightedNeg().toString());
    extensionMap.put("BinPosRate", columnConfig.getBinPosRate().toString());
    extensionMap.put("BinWOE", calculateWoe(columnConfig.getBinCountPos(), columnConfig.getBinCountNeg()).toString());
    extensionMap.put("KS", Double.toString(columnConfig.getKs()));
    extensionMap.put("IV", Double.toString(columnConfig.getIv()));
    List<Extension> extensions = createExtensions(extensionMap);
    conStats.addExtensions(extensions.toArray(new Extension[extensions.size()]));
    return conStats;
}
Also used : Extension(org.dmg.pmml.Extension) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ContStats(org.dmg.pmml.ContStats) Interval(org.dmg.pmml.Interval)

Example 3 with Interval

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

the class KiePMMLIntervalInstanceFactoryTest method getKiePMMLInterval.

@Test
public void getKiePMMLInterval() {
    Interval toConvert = getRandomInterval();
    KiePMMLInterval retrieved = KiePMMLIntervalInstanceFactory.getKiePMMLInterval(toConvert);
    commonVerifyKiePMMLInterval(retrieved, toConvert);
}
Also used : InstanceFactoriesTestCommon.commonVerifyKiePMMLInterval(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLInterval) KiePMMLInterval(org.kie.pmml.commons.model.expressions.KiePMMLInterval) Interval(org.dmg.pmml.Interval) InstanceFactoriesTestCommon.commonVerifyKiePMMLInterval(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLInterval) KiePMMLInterval(org.kie.pmml.commons.model.expressions.KiePMMLInterval) PMMLModelTestUtils.getRandomInterval(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomInterval) Test(org.junit.Test)

Example 4 with Interval

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

the class FormulaUtil method createDiscretize.

private static Discretize createDiscretize(FieldName 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 5 with Interval

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

the class BucketizerConverter method encodeFeatures.

@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder) {
    Bucketizer transformer = getTransformer();
    Feature feature = encoder.getOnlyFeature(transformer.getInputCol());
    ContinuousFeature continuousFeature = feature.toContinuousFeature();
    Discretize discretize = new Discretize(continuousFeature.getName());
    List<String> categories = new ArrayList<>();
    double[] splits = transformer.getSplits();
    for (int i = 0; i < (splits.length - 1); i++) {
        String category = String.valueOf(i);
        categories.add(category);
        Interval interval = new Interval((i < (splits.length - 2)) ? Interval.Closure.CLOSED_OPEN : Interval.Closure.CLOSED_CLOSED).setLeftMargin(formatMargin(splits[i])).setRightMargin(formatMargin(splits[i + 1]));
        DiscretizeBin discretizeBin = new DiscretizeBin(category, interval);
        discretize.addDiscretizeBins(discretizeBin);
    }
    DerivedField derivedField = encoder.createDerivedField(formatName(transformer), OpType.CATEGORICAL, DataType.INTEGER, discretize);
    return Collections.<Feature>singletonList(new CategoricalFeature(encoder, derivedField, categories));
}
Also used : ArrayList(java.util.ArrayList) Feature(org.jpmml.converter.Feature) ContinuousFeature(org.jpmml.converter.ContinuousFeature) CategoricalFeature(org.jpmml.converter.CategoricalFeature) CategoricalFeature(org.jpmml.converter.CategoricalFeature) ContinuousFeature(org.jpmml.converter.ContinuousFeature) Discretize(org.dmg.pmml.Discretize) Bucketizer(org.apache.spark.ml.feature.Bucketizer) DiscretizeBin(org.dmg.pmml.DiscretizeBin) DerivedField(org.dmg.pmml.DerivedField) Interval(org.dmg.pmml.Interval)

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