(pred_list, label_list, label_size)
return precision, recall, overall_prec, overall_recall, confusion
Helper method that calculates confusion matrix.
Helper method that calculates confusion matrix.
Helper method that calculates confusion matrix .
def calculate_confusion_single(pred_list, label_list, label_size):
    """Helper method that calculates confusion matrix."""
    confusion = np.zeros((label_size, label_size), dtype=np.int32)
    for i in xrange(len(label_list)):
        confusion[label_list[i], pred_list[i]] += 1
    
    tp_fp = np.sum(confusion, axis=0)
    tp_fn = np.sum(confusion, axis=1)
    tp = np.array([confusion[i, i] for i in range(len(confusion))])
    
    precision = tp.astype(np.float32)/(tp_fp+1e-40)
    recall = tp.astype(np.float32)/(tp_fn+1e-40)
    overall_prec = np.float(np.sum(tp))/(np.sum(tp_fp)+1e-40)
    overall_recall = np.float(np.sum(tp))/(np.sum(tp_fn)+1e-40)
    
    return precision, recall, overall_prec, overall_recall, confusion
def calculate_confusion_single ( pred_list , label_list , label_size ) : confusion = np . zeros ( ( label_size , label_size ) , dtype = np . int32 ) for i in xrange ( len ( label_list ) ) : confusion [ label_list [ i ] , pred_list [ i ] ] += 1 tp_fp = np . sum ( confusion , axis = 0 ) tp_fn = np . sum ( confusion , axis = 1 ) tp = np . array ( [ confusion [ i , i ] for i in range ( len ( confusion ) ) ] ) precision = tp . astype ( np . float32 ) / ( tp_fp + 1e-40 ) recall = tp . astype ( np . float32 ) / ( tp_fn + 1e-40 ) overall_prec = np . float ( np . sum ( tp ) ) / ( np . sum ( tp_fp ) + 1e-40 ) overall_recall = np . float ( np . sum ( tp ) ) / ( np . sum ( tp_fn ) + 1e-40 ) return precision , recall , overall_prec , overall_recall , confusion