public String toCSV(){
  StringBuilder builder=new StringBuilder();
  builder.append(",,Predicted Class,\n");
  builder.append(",,");
  for (  T predicted : classes) {
    builder.append(String.format("%s,",predicted));
  }
  builder.append("Total\n");
  String firstColumnLabel="Actual Class,";
  for (  T actual : classes) {
    builder.append(firstColumnLabel);
    firstColumnLabel=",";
    builder.append(String.format("%s,",actual));
    for (    T predicted : classes) {
      builder.append(getCount(actual,predicted));
      builder.append(",");
    }
    builder.append(getActualTotal(actual));
    builder.append("\n");
  }
  builder.append(",Total,");
  for (  T predicted : classes) {
    builder.append(getPredictedTotal(predicted));
    builder.append(",");
  }
  builder.append("\n");
  return builder.toString();
}

public String toCSV ( ) { StringBuilder builder = new StringBuilder ( ) ; builder . append ( ",,Predicted Class,\n" ) ; builder . append ( ",," ) ; for ( T predicted : classes ) { builder . append ( String . format ( "%s," , predicted ) ) ; } builder . append ( "Total\n" ) ; String firstColumnLabel = "Actual Class," ; for ( T actual : classes ) { builder . append ( firstColumnLabel ) ; firstColumnLabel = "," ; builder . append ( String . format ( "%s," , actual ) ) ; for ( T predicted : classes ) { builder . append ( getCount ( actual , predicted ) ) ; builder . append ( "," ) ; } builder . append ( getActualTotal ( actual ) ) ; builder . append ( "\n" ) ; } builder . append ( ",Total," ) ; for ( T predicted : classes ) { builder . append ( getPredictedTotal ( predicted ) ) ; builder . append ( "," ) ; } builder . append ( "\n" ) ; return builder . toString ( ) ; }
outputs the confusionmatrix as comma - separated values for easy import into spreadsheets
