use of org.knime.base.node.mine.regression.RegressionContent in project knime-core by knime.
the class LinReg2LearnerNodeView method modelChanged.
/**
* {@inheritDoc}
*/
@Override
protected void modelChanged() {
LinReg2LearnerNodeModel model = getNodeModel();
StringBuilder buffer = new StringBuilder();
buffer.append("<html>\n");
buffer.append("<head>\n");
buffer.append("<style type=\"text/css\">\n");
buffer.append("body {color:#333333;}");
buffer.append("table {width: 100%;margin: 7px 0 7px 0;}");
buffer.append("th {font-weight: bold;background-color: #aaccff;}");
buffer.append("td,th {padding: 4px 5px; }");
buffer.append(".numeric {text-align: right}");
buffer.append(".odd {background-color:#ddeeff;}");
buffer.append(".even {background-color:#ffffff;}");
buffer.append("</style>\n");
buffer.append("</head>\n");
buffer.append("<body>\n");
buffer.append("<h2>Statistics on Linear Regression</h2>");
if (model.isDataAvailable()) {
RegressionContent content = model.getRegressionContent();
List<String> parameters = content.getParameters();
buffer.append("<table>\n");
buffer.append("<tr>");
buffer.append("<th>Variable</th>");
buffer.append("<th>Coeff.</th>");
buffer.append("<th>Std. Err.</th>");
buffer.append("<th>t-value</th>");
buffer.append("<th>P>|t|</th>");
buffer.append("</tr>");
Map<Pair<String, Integer>, Double> coefficients = content.getCoefficients();
Map<Pair<String, Integer>, Double> stdErrs = content.getStandardErrors();
Map<Pair<String, Integer>, Double> tValues = content.getTValues();
Map<Pair<String, Integer>, Double> pValues = content.getPValues();
boolean odd = true;
for (String parameter : parameters) {
if (odd) {
buffer.append("<tr class=\"odd\">\n");
} else {
buffer.append("<tr class=\"even\">\n");
}
odd = !odd;
buffer.append("<td>");
buffer.append(StringEscapeUtils.escapeHtml(parameter));
buffer.append("</td>\n<td class=\"numeric\">");
Pair<String, Integer> pair = Pair.create(parameter, 1);
String coeff = DoubleFormat.formatDouble(coefficients.get(pair));
buffer.append(coeff);
buffer.append("</td>\n<td class=\"numeric\">");
String stdErr = DoubleFormat.formatDouble(stdErrs.get(pair));
buffer.append(stdErr);
buffer.append("</td>\n<td class=\"numeric\">");
String zScore = DoubleFormat.formatDouble(tValues.get(pair));
buffer.append(zScore);
buffer.append("</td>\n<td class=\"numeric\">");
String pValue = DoubleFormat.formatDouble(pValues.get(pair));
buffer.append(pValue);
buffer.append("</td>\n");
buffer.append("</tr>\n");
}
if (content.getIncludeConstant()) {
if (odd) {
buffer.append("<tr class=\"odd\">\n");
} else {
buffer.append("<tr class=\"even\">\n");
}
buffer.append("<td>");
buffer.append("Intercept");
buffer.append("</td>\n<td class=\"numeric\">");
String intercept = DoubleFormat.formatDouble(content.getIntercept());
buffer.append(intercept);
buffer.append("</td>\n<td class=\"numeric\">");
String stdErr = DoubleFormat.formatDouble(content.getInterceptStdErr());
buffer.append(stdErr);
buffer.append("</td>\n<td class=\"numeric\">");
String tValue = DoubleFormat.formatDouble(content.getInterceptTValue());
buffer.append(tValue);
buffer.append("</td>\n<td class=\"numeric\">");
String pValue = DoubleFormat.formatDouble(content.getInterceptPValue());
buffer.append(pValue);
buffer.append("</td>\n");
buffer.append("</tr>\n");
buffer.append("</tr>\n");
}
buffer.append("</table>\n");
if (!content.getIncludeConstant()) {
buffer.append("Offset Value: ");
String offsetValue = DoubleFormat.formatDouble(content.getOffsetValue());
buffer.append(offsetValue);
buffer.append("<br/>");
}
buffer.append("Multiple R-Squared: ");
String rSquared = DoubleFormat.formatDouble(content.getRSquared());
buffer.append(rSquared);
buffer.append("<br/>");
buffer.append("Adjusted R-Squared: ");
String adjustedRSquared = DoubleFormat.formatDouble(content.getAdjustedRSquared());
buffer.append(adjustedRSquared);
buffer.append("<br/>");
} else {
buffer.append("No parameters available.\n");
}
buffer.append("</body>\n");
buffer.append("</html>\n");
m_pane.setText(buffer.toString());
m_pane.revalidate();
}
use of org.knime.base.node.mine.regression.RegressionContent in project knime-core by knime.
the class LinReg2LinePlotter method updatePaintModel.
/**
* Retrieves the linear regression params, updates the column selection
* boxes appropriately and adds the regression line to the scatterplot.
*/
@Override
public void updatePaintModel() {
DataProvider dataProvider = getDataProvider();
if (dataProvider == null) {
return;
}
RegressionContent content = ((LinReg2DataProvider) dataProvider).getLinRegContent();
if (content == null) {
return;
}
List<String> includedList = content.getCovariates();
String target = content.getSpec().getTargetCols().get(0).getName();
// set the target column to fix
((LinReg2LinePlotterProperties) getProperties()).setTargetColumn(target);
// get the included columns
((LinReg2LinePlotterProperties) getProperties()).setIncludedColumns(includedList.toArray(new String[includedList.size()]));
// update the combo boxes
DataTableSpec spec = getDataProvider().getDataArray(0).getDataTableSpec();
((LinReg2LinePlotterProperties) getProperties()).update(spec);
super.updatePaintModel();
double xMin = ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue();
double xMax = ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue();
String xName = getSelectedXColumn().getName();
if (!xName.equals(target) && includedList.contains(xName)) {
double yMin = getApproximationFor(xName, xMin, content);
double yMax = getApproximationFor(xName, xMax, content);
((LinReg2LineDrawingPane) getDrawingPane()).setLineFirstPoint(getMappedXValue(new DoubleCell(xMin)), getMappedYValue(new DoubleCell(yMin)));
((LinReg2LineDrawingPane) getDrawingPane()).setLineLastPoint(getMappedXValue(new DoubleCell(xMax)), getMappedYValue(new DoubleCell(yMax)));
getDrawingPane().repaint();
}
}
use of org.knime.base.node.mine.regression.RegressionContent in project knime-core by knime.
the class LinReg2LinePlotter method updateSize.
/**
* First calls super then adapts the regression line.
*/
@Override
public void updateSize() {
if (getXAxis() == null || getXAxis().getCoordinate() == null || getYAxis() == null || getYAxis().getCoordinate() == null) {
return;
}
super.updateSize();
DataProvider dataProvider = getDataProvider();
if (dataProvider == null) {
return;
}
RegressionContent content = ((LinReg2DataProvider) dataProvider).getLinRegContent();
if (content == null) {
return;
}
double xMin = ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue();
double xMax = ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue();
String xName = getSelectedXColumn().getName();
List<String> includedList = content.getCovariates();
String target = content.getSpec().getTargetCols().get(0).getName();
if (!xName.equals(target) && includedList.contains(xName)) {
double yMin = getApproximationFor(xName, xMin, content);
double yMax = getApproximationFor(xName, xMax, content);
((LinReg2LineDrawingPane) getDrawingPane()).setLineFirstPoint(getMappedXValue(new DoubleCell(xMin)), getMappedYValue(new DoubleCell(yMin)));
((LinReg2LineDrawingPane) getDrawingPane()).setLineLastPoint(getMappedXValue(new DoubleCell(xMax)), getMappedYValue(new DoubleCell(yMax)));
}
}
Aggregations