# Example of Calculating a Confusion Matrix
# calculate a confusion matrix
def confusion_matrix(actual, predicted):
    unique = set(actual)
    matrix = [list() for x in range(len(unique))]
    for i in range(len(unique)):
        matrix[i] = [0 for x in range(len(unique))]
    lookup = dict()
    for i, value in enumerate(unique):
        lookup[value] = i
    for i in range(len(actual)):
        x = lookup[actual[i]]
        y = lookup[predicted[i]]
        matrix[y][x] += 1
    return unique, matrix


# Test confusion matrix with integers
if __name__ == '__main__':
    actual = [0,0,0,0,0,1,1,1,1,1]
    predicted = [0,1,1,0,0,1,0,1,1,1]
    unique, matrix = confusion_matrix(actual, predicted)
    print(unique)
    print(matrix)