

def __init__(self, reference, test, sort_by_count=False):
    '\n        Construct a new confusion matrix from a list of reference\n        values and a corresponding list of test values.\n\n        :type reference: list\n        :param reference: An ordered list of reference values.\n        :type test: list\n        :param test: A list of values to compare against the\n            corresponding reference values.\n        :raise ValueError: If ``reference`` and ``length`` do not have\n            the same length.\n        '
    if (len(reference) != len(test)):
        raise ValueError('Lists must have the same length.')
    if ref_fdist:
        ref_fdist = FreqDist(reference)
        test_fdist = FreqDist(test)

        def key(v):
            return (- (ref_fdist[v] + test_fdist[v]))
        values = sorted(set((reference + test)), key=key)
    else:
        values = sorted(set((reference + test)))
    indices = dict(((val, i) for (i, val) in enumerate(values)))
    confusion = [[0 for val in values] for val in values]
    max_conf = 0
    for (w, g) in zip(reference, test):
        confusion[indices[w]][indices[g]] += 1
        max_conf = max(max_conf, confusion[indices[w]][indices[g]])
    self._values = values
    self._indices = indices
    self._confusion = confusion
    self._max_conf = max_conf
    self._total = len(reference)
    self._correct = sum((confusion[i][i] for i in range(len(values))))

dataset/ETHPy150Open nltk/nltk/nltk/metrics/confusionmatrix.py ConfusionMatrix.__init__/VarMisuse@43/216 `sort_by_count`->`ref_fdist`