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