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

Function test

pattern/metrics.py:125–142  ·  view source on GitHub ↗

Returns an (accuracy, precision, recall, F1-score)-tuple. With average=None, precision & recall are computed for the positive class (True). With average=MACRO, precision & recall for positive and negative class are macro-averaged.

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

Source from the content-addressed store, hash-verified

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.
127 With average=None, precision & recall are computed for the positive class (True).
128 With average=MACRO, precision & recall for positive and negative class are macro-averaged.
129 """
130 TP, TN, FP, FN = confusion_matrix(classify, documents)
131 A = float(TP + TN) / ((TP + TN + FP + FN) or 1)
132 P1 = float(TP) / ((TP + FP) or 1) # positive class precision
133 R1 = float(TP) / ((TP + FN) or 1) # positive class recall
134 P0 = float(TN) / ((TN + FN) or 1) # negative class precision
135 R0 = float(TN) / ((TN + FP) or 1) # negative class recall
136 if average is None:
137 P, R = (P1, R1)
138 if average == MACRO:
139 P, R = ((P1 + P0) / 2,
140 (R1 + R0) / 2)
141 F1 = 2 * P * R / ((P + R) or 1)
142 return (A, P, R, F1)
143
144def accuracy(classify=lambda document:False, documents=[], average=None):
145 """ Returns the percentage of correct classifications (true positives + true negatives).

Callers 10

test_modalityMethod · 0.90
test_sentimentMethod · 0.90
test_sentimentMethod · 0.90
test_sentimentMethod · 0.90
accuracyFunction · 0.85
precisionFunction · 0.85
recallFunction · 0.85
F1Function · 0.85
FFunction · 0.85

Calls 1

confusion_matrixFunction · 0.85

Tested by 5

test_modalityMethod · 0.72
test_sentimentMethod · 0.72
test_sentimentMethod · 0.72
test_sentimentMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…