public String toHTML(){
  StringBuilder builder=new StringBuilder();
  int numClasses=classes.size();
  builder.append("<table>\n");
  builder.append("<tr><th class=\"empty-space\" colspan=\"2\" rowspan=\"2\">");
  builder.append(String.format("<th class=\"predicted-class-header\" colspan=\"%d\">Predicted Class</th></tr>\n",numClasses + 1));
  builder.append("<tr>");
  for (  T predicted : classes) {
    builder.append("<th class=\"predicted-class-header\">");
    builder.append(predicted);
    builder.append("</th>");
  }
  builder.append("<th class=\"predicted-class-header\">Total</th>");
  builder.append("</tr>\n");
  String firstColumnLabel=String.format("<tr><th class=\"actual-class-header\" rowspan=\"%d\">Actual Class</th>",numClasses + 1);
  for (  T actual : classes) {
    builder.append(firstColumnLabel);
    firstColumnLabel="<tr>";
    builder.append(String.format("<th class=\"actual-class-header\" >%s</th>",actual));
    for (    T predicted : classes) {
      builder.append("<td class=\"count-element\">");
      builder.append(getCount(actual,predicted));
      builder.append("</td>");
    }
    builder.append("<td class=\"count-element\">");
    builder.append(getActualTotal(actual));
    builder.append("</td>");
    builder.append("</tr>\n");
  }
  builder.append("<tr><th class=\"actual-class-header\">Total</th>");
  for (  T predicted : classes) {
    builder.append("<td class=\"count-element\">");
    builder.append(getPredictedTotal(predicted));
    builder.append("</td>");
  }
  builder.append("<td class=\"empty-space\"></td>\n");
  builder.append("</tr>\n");
  builder.append("</table>\n");
  return builder.toString();
}

public String toHTML ( ) { StringBuilder builder = new StringBuilder ( ) ; int numClasses = classes . size ( ) ; builder . append ( "<table>\n" ) ; builder . append ( "<tr><th class=\"empty-space\" colspan=\"2\" rowspan=\"2\">" ) ; builder . append ( String . format ( "<th class=\"predicted-class-header\" colspan=\"%d\">Predicted Class</th></tr>\n" , numClasses + 1 ) ) ; builder . append ( "<tr>" ) ; for ( T predicted : classes ) { builder . append ( "<th class=\"predicted-class-header\">" ) ; builder . append ( predicted ) ; builder . append ( "</th>" ) ; } builder . append ( "<th class=\"predicted-class-header\">Total</th>" ) ; builder . append ( "</tr>\n" ) ; String firstColumnLabel = String . format ( "<tr><th class=\"actual-class-header\" rowspan=\"%d\">Actual Class</th>" , numClasses + 1 ) ; for ( T actual : classes ) { builder . append ( firstColumnLabel ) ; firstColumnLabel = "<tr>" ; builder . append ( String . format ( "<th class=\"actual-class-header\" >%s</th>" , actual ) ) ; for ( T predicted : classes ) { builder . append ( "<td class=\"count-element\">" ) ; builder . append ( getCount ( actual , predicted ) ) ; builder . append ( "</td>" ) ; } builder . append ( "<td class=\"count-element\">" ) ; builder . append ( getActualTotal ( actual ) ) ; builder . append ( "</td>" ) ; builder . append ( "</tr>\n" ) ; } builder . append ( "<tr><th class=\"actual-class-header\">Total</th>" ) ; for ( T predicted : classes ) { builder . append ( "<td class=\"count-element\">" ) ; builder . append ( getPredictedTotal ( predicted ) ) ; builder . append ( "</td>" ) ; } builder . append ( "<td class=\"empty-space\"></td>\n" ) ; builder . append ( "</tr>\n" ) ; builder . append ( "</table>\n" ) ; return builder . toString ( ) ; }
outputs confusion matrix in an html table . cascading style sheets ( css ) can control the table ' s appearance by defining the empty - space , actual - count - header , predicted - class - header , and count - element classes . for example
