public String stats ( int printPrecision ) { StringBuilder sb = new StringBuilder ( ) ; //Report: Accuracy, precision, recall, F1. Then: confusion matrix int maxLabelsLength = 15 ; if ( labels != null ) { for ( String s : labels ) { maxLabelsLength = Math . max ( s . length ( ) , maxLabelsLength ) ; } } String subPattern = "%-12." + printPrecision + "f" ; String pattern = "%-" + ( maxLabelsLength + 5 ) + "s" //Label + subPattern + subPattern + subPattern + subPattern //Accuracy, f1, precision, recall + "%-8d%-7d%-7d%-7d%-7d" ; //Total count, TP, TN, FP, FN String patternHeader = "%-" + ( maxLabelsLength + 5 ) + "s%-12s%-12s%-12s%-12s%-8s%-7s%-7s%-7s%-7s" ; List < String > headerNames = Arrays . asList ( "Label" , "Accuracy" , "F1" , "Precision" , "Recall" , "Total" , "TP" , "TN" , "FP" , "FN" ) ; if ( rocBinary != null ) { patternHeader += "%-12s" ; pattern += subPattern ; headerNames = new ArrayList <> ( headerNames ) ; headerNames . add ( "AUC" ) ; } String header = String . format ( patternHeader , headerNames . toArray ( ) ) ; sb . append ( header ) ; if ( countTrueNegative != null ) { for ( int i = 0 ; i < countTrueNegative . length ; i ++ ) { int totalCount = totalCount ( i ) ; double acc = accuracy ( i ) ; double f1 = f1 ( i ) ; double precision = precision ( i ) ; double recall = recall ( i ) ; String label = ( labels == null ? String . valueOf ( i ) : labels . get ( i ) ) ; List < Object > args = Arrays . < Object > asList ( label , acc , f1 , precision , recall , totalCount , truePositives ( i ) , trueNegatives ( i ) , falsePositives ( i ) , falseNegatives ( i ) ) ; if ( rocBinary != null ) { args = new ArrayList <> ( args ) ; args . add ( rocBinary . calculateAUC ( i ) ) ; } sb . append ( "\n" ) . append ( String . format ( pattern , args . toArray ( ) ) ) ; } if ( decisionThreshold != null ) { sb . append ( "\nPer-output decision thresholds: " ) . append ( Arrays . toString ( decisionThreshold . dup ( ) . data ( ) . asFloat ( ) ) ) ; } } else { //Empty evaluation sb . append ( "\n-- No Data --\n" ) ; } return sb . toString ( ) ; }
Get a String representation of the EvaluationBinary class using the specified precision