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

Method auc

pattern/vector/__init__.py:1831–1844  ·  view source on GitHub ↗

Returns the area under the ROC-curve. Returns the probability (0.0-1.0) that a classifier will rank a random positive document (True) higher than a random negative one (False).

(self, documents=[], k=10)

Source from the content-addressed store, hash-verified

1829 return ConfusionMatrix(self.classify, documents)
1830
1831 def auc(self, documents=[], k=10):
1832 """ Returns the area under the ROC-curve.
1833 Returns the probability (0.0-1.0) that a classifier will rank
1834 a random positive document (True) higher than a random negative one (False).
1835 """
1836 roc = [(0.0, 0.0), (1.0, 1.0)]
1837 for type, TP, TN, FP, FN in self.confusion_matrix(documents).split():
1838 x = FPR = float(FP) / ((FP + TN) or 1) # false positive rate
1839 y = TPR = float(TP) / ((TP + FN) or 1) # true positive rate
1840 roc.append((x, y))
1841 #print "%s\t%s %s %s %s\t %s %s" % (TP, TN, FP, FN, FPR, TPR)
1842 roc = sorted(roc)
1843 # Trapzoidal rule: area = (a + b) * h / 2, where a=y0, b=y1 and h=x1-x0.
1844 return sum(0.5 * (x1 - x0) * (y1 + y0) for (x0, y0), (x1, y1) in sorted(izip(roc, roc[1:])))
1845
1846 def save(self, path):
1847 self.test = None # Can't pickle instancemethods.

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected