MCPcopy Index your code
hub / github.com/clips/pattern / confusion_matrix

Function confusion_matrix

pattern/metrics.py:101–123  ·  view source on GitHub ↗

Returns the performance of a binary classification task (i.e., predicts True or False) as a tuple of (TP, TN, FP, FN): - TP: true positives = correct hits, - TN: true negatives = correct rejections, - FP: false positives = false alarm (= type I error), -

(classify=lambda document: False, documents=[(None,False)])

Source from the content-addressed store, hash-verified

99MACRO = "macro"
100
101def confusion_matrix(classify=lambda document: False, documents=[(None,False)]):
102 """ Returns the performance of a binary classification task (i.e., predicts True or False)
103 as a tuple of (TP, TN, FP, FN):
104 - TP: true positives = correct hits,
105 - TN: true negatives = correct rejections,
106 - FP: false positives = false alarm (= type I error),
107 - FN: false negatives = misses (= type II error).
108 The given classify() function returns True or False for a document.
109 The list of documents contains (document, bool)-tuples for testing,
110 where True means a document that should be identified as True by classify().
111 """
112 TN = TP = FN = FP = 0
113 for document, b1 in documents:
114 b2 = classify(document)
115 if b1 and b2:
116 TP += 1 # true positive
117 elif not b1 and not b2:
118 TN += 1 # true negative
119 elif not b1 and b2:
120 FP += 1 # false positive (type I error)
121 elif b1 and not b2:
122 FN += 1 # false negative (type II error)
123 return TP, TN, FP, FN
124
125def test(classify=lambda document:False, documents=[], average=None):
126 """ Returns an (accuracy, precision, recall, F1-score)-tuple.

Callers 2

testFunction · 0.85
specificityFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…