use of org.knime.base.node.preproc.autobinner3.AutoBinnerLearnSettings in project knime-core by knime.
the class DBAutoBinner method createPMMLPrepocDiscretize.
/**
* This method creates a {@link PMMLPreprocDiscretize} object and is used in {@link DBAutoBinnerNodeModel}
*
* @param cp {@link CredentialsProvider}
* @param connectionSettings {@link DatabaseQueryConnectionSettings}
* @param dataTableSpec DataTableSpec of incoming {@link BufferedDataTable}
* @return a {@link PMMLPreprocDiscretize} object containing required parameters for binning operation
* @throws SQLException
*/
public PMMLPreprocDiscretize createPMMLPrepocDiscretize(final CredentialsProvider cp, final DatabaseQueryConnectionSettings connectionSettings, final DataTableSpec dataTableSpec) throws SQLException {
final String query = connectionSettings.getQuery();
final StatementManipulator statementManipulator = connectionSettings.getUtility().getStatementManipulator();
AutoBinnerLearnSettings settings = getSettings();
String[] includeCols = settings.getFilterConfiguration().applyTo(dataTableSpec).getIncludes();
if (includeCols.length == 0) {
return createDisretizeOp(new LinkedHashMap<>());
}
StringBuilder minMaxQuery = new StringBuilder();
minMaxQuery.append("SELECT");
for (int i = 0; i < includeCols.length; i++) {
minMaxQuery.append(" MAX(" + statementManipulator.quoteIdentifier(includeCols[i]) + ") " + statementManipulator.quoteIdentifier("max_" + includeCols[i]) + ",");
minMaxQuery.append(" MIN(" + statementManipulator.quoteIdentifier(includeCols[i]) + ") " + statementManipulator.quoteIdentifier("min_" + includeCols[i]));
if (i < includeCols.length - 1) {
minMaxQuery.append(",");
}
}
minMaxQuery.append(" FROM (" + query + ") T");
HashMap<String, Pair<Double, Double>> maxAndMin = connectionSettings.execute(cp, conn -> {
double max = 0;
double min = 0;
HashMap<String, Pair<Double, Double>> maxMinMap = new LinkedHashMap<>();
try (ResultSet valueSet = conn.createStatement().executeQuery(minMaxQuery.toString())) {
while (valueSet.next()) {
for (int i = 0; i < includeCols.length; i++) {
max = valueSet.getDouble("max_" + includeCols[i]);
min = valueSet.getDouble("min_" + includeCols[i]);
maxMinMap.put(includeCols[i], new Pair<Double, Double>(min, max));
}
}
}
return maxMinMap;
});
int number = settings.getBinCount();
Map<String, double[]> edgesMap = new LinkedHashMap<>();
for (Entry<String, Pair<Double, Double>> entry : maxAndMin.entrySet()) {
double[] edges = AutoBinner.calculateBounds(number, entry.getValue().getFirst(), entry.getValue().getSecond());
if (settings.getIntegerBounds()) {
edges = AutoBinner.toIntegerBoundaries(edges);
}
edgesMap.put(entry.getKey(), edges);
}
return createDisretizeOp(edgesMap);
}
use of org.knime.base.node.preproc.autobinner3.AutoBinnerLearnSettings in project knime-core by knime.
the class DBAutoBinnerNodeModel method validateSettings.
/**
* {@inheritDoc}
*/
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
AutoBinnerLearnSettings s = new AutoBinnerLearnSettings();
s.loadSettings(settings);
}
Aggregations