use of org.knime.base.node.preproc.autobinner.pmml.PMMLDiscretize in project knime-core by knime.
the class AutoBinner method createDisretizeOp.
private PMMLPreprocDiscretize createDisretizeOp(final Map<String, double[]> edgesMap) {
Map<String, List<PMMLDiscretizeBin>> binMap = createBins(edgesMap);
List<String> names = new ArrayList<String>();
Map<String, PMMLDiscretize> discretize = new HashMap<String, PMMLDiscretize>();
for (String target : m_settings.getTargetColumn()) {
String binnedCol = m_settings.getReplaceColumn() ? target : target + " [Binned]";
names.add(binnedCol);
discretize.put(binnedCol, new PMMLDiscretize(target, binMap.get(target)));
}
DisretizeConfiguration config = new DisretizeConfiguration(names, discretize);
PMMLPreprocDiscretize op = new PMMLPreprocDiscretize(config);
return op;
}
use of org.knime.base.node.preproc.autobinner.pmml.PMMLDiscretize in project knime-core by knime.
the class DBAutoBinner method translate.
/**
* This method translates a {@link PMMLPreprocDiscretize} object into {@link PMMLPortObject}.
*
* @param pmmlDiscretize {@link PMMLPreprocDiscretize} object
* @param dataTableSpec {@link DataTableSpec} if incoming {@link BufferedDataTable}
* @return a {@link PMMLPortObject} containing required parameters for binning operation
*/
public static PMMLPortObject translate(final PMMLPreprocDiscretize pmmlDiscretize, final DataTableSpec dataTableSpec) {
final Map<String, Bin[]> columnToBins = new HashMap<>();
final Map<String, String> columnToAppend = new HashMap<>();
List<String> replacedColumnNames = pmmlDiscretize.getConfiguration().getNames();
for (String replacedColumnName : replacedColumnNames) {
PMMLDiscretize discretize = pmmlDiscretize.getConfiguration().getDiscretize(replacedColumnName);
List<PMMLDiscretizeBin> bins = discretize.getBins();
String originalColumnName = discretize.getField();
if (replacedColumnName.equals(originalColumnName)) {
// wenn replaced, dann nicht anhängen
columnToAppend.put(originalColumnName, null);
} else {
// nicht replaced -> anhängen
columnToAppend.put(originalColumnName, replacedColumnName);
}
NumericBin[] numericBin = new NumericBin[bins.size()];
int counter = 0;
for (PMMLDiscretizeBin bin : bins) {
String binName = bin.getBinValue();
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) {
Closure closure = interval.getClosure();
switch(closure) {
case openClosed:
leftOpen = true;
rightOpen = false;
break;
case openOpen:
leftOpen = true;
rightOpen = true;
break;
case closedOpen:
leftOpen = false;
rightOpen = true;
case closedClosed:
leftOpen = false;
rightOpen = false;
break;
default:
leftOpen = true;
rightOpen = false;
break;
}
leftMargin = interval.getLeftMargin();
rightMargin = interval.getRightMargin();
}
numericBin[counter] = new NumericBin(binName, leftOpen, leftMargin, rightOpen, rightMargin);
counter++;
}
columnToBins.put(originalColumnName, numericBin);
}
// ColumnRearranger createColReg = createColReg(dataTableSpec, columnToBins, columnToAppended);
DataTableSpec newDataTableSpec = createNewDataTableSpec(dataTableSpec, columnToAppend);
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(newDataTableSpec);
PMMLPortObject pmmlPortObject = new PMMLPortObject(pmmlSpecCreator.createSpec(), null, newDataTableSpec);
PMMLBinningTranslator trans = new PMMLBinningTranslator(columnToBins, columnToAppend, new DerivedFieldMapper(pmmlPortObject));
TransformationDictionary exportToTransDict = trans.exportToTransDict();
pmmlPortObject.addGlobalTransformations(exportToTransDict);
return pmmlPortObject;
}
use of org.knime.base.node.preproc.autobinner.pmml.PMMLDiscretize in project knime-core by knime.
the class AutoBinner method createDisretizeOp.
private PMMLPreprocDiscretize createDisretizeOp(final Map<String, double[]> edgesMap) {
Map<String, List<PMMLDiscretizeBin>> binMap = createBins(edgesMap);
List<String> names = new ArrayList<String>();
Map<String, PMMLDiscretize> discretize = new HashMap<String, PMMLDiscretize>();
for (String target : m_settings.getTargetColumn()) {
String binnedCol = m_settings.getReplaceColumn() ? target : target + " [Binned]";
names.add(binnedCol);
discretize.put(binnedCol, new PMMLDiscretize(target, binMap.get(target)));
}
DisretizeConfiguration config = new DisretizeConfiguration(names, discretize);
PMMLPreprocDiscretize op = new PMMLPreprocDiscretize(config);
return op;
}
use of org.knime.base.node.preproc.autobinner.pmml.PMMLDiscretize in project knime-core by knime.
the class AutoBinner method createDisretizeOp.
/**
* @param edgesMap the boundary map
* @return the {@link PMMLPreprocDiscretize} model
*/
protected PMMLPreprocDiscretize createDisretizeOp(final Map<String, double[]> edgesMap) {
Map<String, List<PMMLDiscretizeBin>> binMap = createBins(edgesMap);
List<String> names = new ArrayList<String>();
Map<String, PMMLDiscretize> discretize = new HashMap<String, PMMLDiscretize>();
for (String target : m_included) {
String binnedCol = m_settings.getReplaceColumn() ? target : target + " [Binned]";
names.add(binnedCol);
discretize.put(binnedCol, new PMMLDiscretize(target, binMap.get(target)));
}
DisretizeConfiguration config = new DisretizeConfiguration(names, discretize);
PMMLPreprocDiscretize op = new PMMLPreprocDiscretize(config);
return op;
}
Aggregations