def compute_accuracy(confusionMatrix): 
    """
    Compute accuracy based on a Confusion Matrix 
    with prediction on rows 
    and truth on columns.
    """  
    correct = 0
    for elem in range(confusionMatrix.shape[0]):
        correct += confusionMatrix[elem, elem] 
    tot = confusionMatrix.sum()
    return correct / tot