use of org.knime.core.data.DataCell in project knime-core by knime.
the class LogRegLearnerNodeDialogPane method createTargetOptionsPanel.
/**
* Create options panel for the target.
*/
private JPanel createTargetOptionsPanel() {
JPanel p = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0;
c.weighty = 0;
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.BASELINE_LEADING;
c.insets = new Insets(5, 5, 0, 0);
p.add(new JLabel("Target Column:"), c);
c.gridx++;
@SuppressWarnings("unchecked") final ColumnSelectionPanel columnSelectionPanel = new ColumnSelectionPanel(new EmptyBorder(0, 0, 0, 0), NominalValue.class);
m_selectionPanel = columnSelectionPanel;
m_selectionPanel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
updateTargetCategories((DataCell) m_targetReferenceCategory.getSelectedItem());
}
});
p.add(m_selectionPanel, c);
c.gridx = 0;
c.gridy++;
p.add(new JLabel("Reference Category:"), c);
c.gridx++;
m_targetReferenceCategory = new JComboBox<>();
p.add(m_targetReferenceCategory, c);
c.gridx = 0;
c.gridy++;
c.gridwidth = 3;
c.weightx = 1;
m_notSortTarget = new JCheckBox("Use order from target column domain (only relevant for output representation)");
p.add(m_notSortTarget, c);
m_selectionPanel.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
Object selected = e.getItem();
if (selected instanceof DataColumnSpec) {
m_filterPanel.resetHiding();
m_filterPanel.hideNames((DataColumnSpec) selected);
}
}
});
return p;
}
use of org.knime.core.data.DataCell in project knime-core by knime.
the class LogisticRegressionContent method createTablePortObject.
/**
* Creates a BufferedDataTable with the
* @param exec The execution context
* @return a port object
*/
public BufferedDataTable createTablePortObject(final ExecutionContext exec) {
DataTableSpec tableOutSpec = new DataTableSpec("Coefficients and Statistics", new String[] { "Logit", "Variable", "Coeff.", "Std. Err.", "z-score", "P>|z|" }, new DataType[] { StringCell.TYPE, StringCell.TYPE, DoubleCell.TYPE, DoubleCell.TYPE, DoubleCell.TYPE, DoubleCell.TYPE });
BufferedDataContainer dc = exec.createDataContainer(tableOutSpec);
List<DataCell> logits = this.getLogits();
List<String> parameters = this.getParameters();
int c = 0;
for (DataCell logit : logits) {
Map<String, Double> coefficients = this.getCoefficients(logit);
Map<String, Double> stdErrs = this.getStandardErrors(logit);
Map<String, Double> zScores = this.getZScores(logit);
Map<String, Double> pValues = this.getPValues(logit);
for (String parameter : parameters) {
List<DataCell> cells = new ArrayList<DataCell>();
cells.add(new StringCell(logit.toString()));
cells.add(new StringCell(parameter));
cells.add(new DoubleCell(coefficients.get(parameter)));
cells.add(new DoubleCell(stdErrs.get(parameter)));
cells.add(new DoubleCell(zScores.get(parameter)));
cells.add(new DoubleCell(pValues.get(parameter)));
c++;
dc.addRowToTable(new DefaultRow("Row" + c, cells));
}
List<DataCell> cells = new ArrayList<DataCell>();
cells.add(new StringCell(logit.toString()));
cells.add(new StringCell("Constant"));
cells.add(new DoubleCell(this.getIntercept(logit)));
cells.add(new DoubleCell(this.getInterceptStdErr(logit)));
cells.add(new DoubleCell(this.getInterceptZScore(logit)));
cells.add(new DoubleCell(this.getInterceptPValue(logit)));
c++;
dc.addRowToTable(new DefaultRow("Row" + c, cells));
}
dc.close();
return dc.getTable();
}
use of org.knime.core.data.DataCell in project knime-core by knime.
the class LogisticRegressionContent method load.
/**
* @param parContent the content that holds the internals
* @param spec the data table spec of the training data
* @return a instance with he loaded values
* @throws InvalidSettingsException when data are not well formed
*/
static LogisticRegressionContent load(final ModelContentRO parContent, final DataTableSpec spec) throws InvalidSettingsException {
String target = parContent.getString(CFG_TARGET);
String[] learningCols = parContent.getStringArray(CFG_LEARNING_COLS);
PMMLPortObjectSpec pmmlSpec = createSpec(spec, target, learningCols);
String[] factors = parContent.getStringArray(CFG_FACTORS);
String[] covariates = parContent.getStringArray(CFG_COVARIATES);
double[] coeff = parContent.getDoubleArray(CFG_COEFFICIENTS);
double likelihood = parContent.getDouble(CFG_LOG_LIKELIHOOD);
double[] covMat = parContent.getDoubleArray(CFG_COVARIANCE_MATRIX);
int iter = parContent.getInt(CFG_ITER);
// introduced in 2.9
DataCell targetReferenceCategory = parContent.getDataCell(CFG_TARGET_REFERENCE_CATEGORY, null);
boolean sortTargetCategories = parContent.getBoolean(CFG_SORT_TARGET_CATEGORIES, true);
boolean sortFactorsCategories = parContent.getBoolean(CFG_SORT_FACTORS_CATEGORIES, true);
return new LogisticRegressionContent(pmmlSpec, Arrays.asList(factors), Arrays.asList(covariates), targetReferenceCategory, sortTargetCategories, sortFactorsCategories, toMatrix(coeff, coeff.length), likelihood, toMatrix(covMat, coeff.length), iter);
}
use of org.knime.core.data.DataCell in project knime-core by knime.
the class LogisticRegressionContent method getValues.
private Map<String, Double> getValues(final DataCell logit, final RealMatrix matrix) {
assert m_targetCategories.contains(logit);
Map<String, Double> coefficients = new HashMap<String, Double>();
int pCount = m_beta.getColumnDimension() / (m_targetCategories.size() - 1);
int p = 1;
for (String colName : m_outSpec.getLearningFields()) {
if (m_factorList.contains(colName)) {
Iterator<DataCell> designIter = m_factorDomainValues.get(colName).iterator();
// Omit first
designIter.next();
while (designIter.hasNext()) {
DataCell dvValue = designIter.next();
String variable = colName + "=" + dvValue;
int k = m_targetCategories.indexOf(logit);
double coeff = matrix.getEntry(0, p + (k * pCount));
coefficients.put(variable, coeff);
p++;
}
} else {
String variable = colName;
int k = m_targetCategories.indexOf(logit);
if (m_vectorLengths.containsKey(colName)) {
int length = m_vectorLengths.get(colName).intValue();
for (int i = 0; i < length; ++i) {
double coeff = matrix.getEntry(0, p + i + (k * pCount));
coefficients.put(VectorHandling.valueAt(variable, i), coeff);
}
p += length;
} else {
double coeff = matrix.getEntry(0, p + (k * pCount));
coefficients.put(variable, coeff);
p++;
}
}
}
return coefficients;
}
use of org.knime.core.data.DataCell in project knime-core by knime.
the class LogisticRegressionContent method getParameters.
/**
* Returns the parameters. The follow the notation rule:
* - for covariate (numeric learning column):
* "column_name"
* - for factors (nominal learning columns) there are n-1 entries
* when n is the number of domain values:
* "column_name=domain_value"
* @return the parameters
*/
public List<String> getParameters() {
List<String> parameters = new ArrayList<String>();
for (String colName : m_outSpec.getLearningFields()) {
if (m_factorList.contains(colName)) {
Iterator<DataCell> designIter = m_factorDomainValues.get(colName).iterator();
// Omit first
designIter.next();
while (designIter.hasNext()) {
DataCell dvValue = designIter.next();
String variable = colName + "=" + dvValue;
parameters.add(variable);
}
} else {
String variable = colName;
if (m_vectorLengths.containsKey(colName)) {
int length = m_vectorLengths.get(colName).intValue();
for (int i = 0; i < length; ++i) {
parameters.add(VectorHandling.valueAt(variable, i));
}
} else {
parameters.add(variable);
}
}
}
return parameters;
}
Aggregations