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

Method _test

pattern/vector/__init__.py:1799–1822  ·  view source on GitHub ↗

Returns an (accuracy, precision, recall, F1-score)-tuple for the given documents, with values between 0.0 and 1.0 (0-100%). Accuracy is the percentage of correct predictions for the given test set, but this metric can be misleading (e.g., classifier *always* pred

(self, documents=[], target=None, **kwargs)

Source from the content-addressed store, hash-verified

1797 return cls(train=d[:i]).test(d[i:])
1798
1799 def _test(self, documents=[], target=None, **kwargs):
1800 """ Returns an (accuracy, precision, recall, F1-score)-tuple for the given documents,
1801 with values between 0.0 and 1.0 (0-100%).
1802 Accuracy is the percentage of correct predictions for the given test set,
1803 but this metric can be misleading (e.g., classifier *always* predicts True).
1804 Precision is the percentage of predictions that were correct.
1805 Recall is the percentage of documents that were correctly labeled.
1806 F1-score is the harmonic mean of precision and recall.
1807 """
1808 A = [] # Accuracy.
1809 P = [] # Precision.
1810 R = [] # Recall.
1811 for type, TP, TN, FP, FN in self.confusion_matrix(documents).split():
1812 if type == target or target is None:
1813 # Calculate precision & recall per class.
1814 A.append(float(TP + TN) / ((TP + TN + FP + FN)))
1815 P.append(float(TP) / ((TP + FP) or 1))
1816 R.append(float(TP) / ((TP + FN) or 1))
1817 # Macro-averaged:
1818 A = sum(A) / (len(A) or 1)
1819 P = sum(P) / (len(P) or 1)
1820 R = sum(R) / (len(R) or 1)
1821 F = 2.0 * P * R / ((P + R) or 1)
1822 return A, P, R, F
1823
1824 def confusion_matrix(self, documents=[]):
1825 """ Returns the confusion matrix for the given test data,

Callers

nothing calls this directly

Calls 5

confusion_matrixMethod · 0.95
sumFunction · 0.85
lenFunction · 0.85
splitMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected