Search in sources :

Example 1 with PMMLInterval

use of org.knime.core.util.binning.auto.pmml.PMMLInterval in project knime-core by knime.

the class AutoBinnerUtility method createBins.

private static Map<String, List<PMMLDiscretizeBin>> createBins(final AutoBinnerLearnSettings settings, final Map<String, double[]> edgesMap, final String[] includeCols) {
    final Map<String, List<PMMLDiscretizeBin>> binMap = new HashMap<String, List<PMMLDiscretizeBin>>();
    for (final String target : includeCols) {
        if (isTargetValid(edgesMap, target)) {
            final double[] edges = edgesMap.get(target);
            final String[] binNames;
            if (BinNaming.NUMBERED == settings.getBinNaming()) {
                binNames = getNumberedBinNames(edges.length - 1);
            } else if (BinNaming.EDGES == settings.getBinNaming()) {
                binNames = getEdgedBinNames(edges, settings);
            } else {
                // BinNaming.MIDPOINTS
                binNames = getMidPointsBinNames(edges, settings);
            }
            final List<PMMLDiscretizeBin> bins = new ArrayList<PMMLDiscretizeBin>();
            bins.add(new PMMLDiscretizeBin(binNames[0], Arrays.asList(new PMMLInterval(edges[0], edges[1], Closure.CLOSED_CLOSED))));
            for (int i = 1; i < binNames.length; i++) {
                bins.add(new PMMLDiscretizeBin(binNames[i], Arrays.asList(new PMMLInterval(edges[i], edges[i + 1], Closure.OPEN_CLOSED))));
            }
            binMap.put(target, bins);
        } else {
            binMap.put(target, new ArrayList<PMMLDiscretizeBin>());
        }
    }
    return binMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) PMMLDiscretizeBin(org.knime.core.util.binning.auto.pmml.PMMLDiscretizeBin) PMMLInterval(org.knime.core.util.binning.auto.pmml.PMMLInterval)

Example 2 with PMMLInterval

use of org.knime.core.util.binning.auto.pmml.PMMLInterval in project knime-core by knime.

the class AutoBinnerUtility method getNumericBin.

private static NumericBin getNumericBin(final PMMLDiscretizeBin bin) {
    final String binName = bin.getBinValue();
    final List<PMMLInterval> intervals = bin.getIntervals();
    boolean leftOpen = false;
    boolean rightOpen = false;
    double leftMargin = 0;
    double rightMargin = 0;
    // always returns only one interval
    for (PMMLInterval interval : intervals) {
        final Closure closure = interval.getClosure();
        switch(closure) {
            case OPEN_CLOSED:
                leftOpen = true;
                rightOpen = false;
                break;
            case OPEN_OPEN:
                leftOpen = true;
                rightOpen = true;
                break;
            case CLOSED_OPEN:
                leftOpen = false;
                rightOpen = true;
                break;
            case CLOSED_CLOSED:
                leftOpen = false;
                rightOpen = false;
                break;
            default:
                leftOpen = true;
                rightOpen = false;
                break;
        }
        leftMargin = interval.getLeftMargin();
        rightMargin = interval.getRightMargin();
    }
    return new NumericBin(binName, leftOpen, leftMargin, rightOpen, rightMargin);
}
Also used : NumericBin(org.knime.core.util.binning.numeric.NumericBin) Closure(org.knime.core.util.binning.auto.pmml.Closure) PMMLInterval(org.knime.core.util.binning.auto.pmml.PMMLInterval)

Aggregations

PMMLInterval (org.knime.core.util.binning.auto.pmml.PMMLInterval)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Closure (org.knime.core.util.binning.auto.pmml.Closure)1 PMMLDiscretizeBin (org.knime.core.util.binning.auto.pmml.PMMLDiscretizeBin)1 NumericBin (org.knime.core.util.binning.numeric.NumericBin)1