ktl014
7/28/2017 - 11:39 PM

how to make confusion matrix without sklearn.metrics From https://stackoverflow.com/questions/2148543/how-to-write-a-confusion-matrix-in-py

how to make confusion matrix without sklearn.metrics

From https://stackoverflow.com/questions/2148543/how-to-write-a-confusion-matrix-in-python

    import numpy
    actual = numpy.array(actual)
    predicted = numpy.array(predicted)

    # calculate the confusion matrix; labels is numpy array of classification labels
    cm = numpy.zeros((len(labels), len(labels)))
    for a, p in zip(actual, predicted):
        cm[a][p] += 1

    # also get the accuracy easily with numpy
    accuracy = (actual == predicted).sum() / float(len(actual))