Returns the ROC curve as an iterator of (x, y)-points, for the given list of (TP, TN, FP, FN)-tuples. The x-axis represents FPR = the false positive rate (1 - specificity). The y-axis represents TPR = the true positive rate.
(tests=[])
| 188 | # See: Tom Fawcett (2005), An Introduction to ROC analysis. |
| 189 | |
| 190 | def roc(tests=[]): |
| 191 | """ Returns the ROC curve as an iterator of (x, y)-points, |
| 192 | for the given list of (TP, TN, FP, FN)-tuples. |
| 193 | The x-axis represents FPR = the false positive rate (1 - specificity). |
| 194 | The y-axis represents TPR = the true positive rate. |
| 195 | """ |
| 196 | x = FPR = lambda TP, TN, FP, FN: float(FP) / ((FP + TN) or 1) |
| 197 | y = TPR = lambda TP, TN, FP, FN: float(TP) / ((TP + FN) or 1) |
| 198 | return sorted([(0.0, 0.0), (1.0, 1.0)] + [(x(*m), y(*m)) for m in tests]) |
| 199 | |
| 200 | def auc(curve=[]): |
| 201 | """ Returns the area under the curve for the given list of (x, y)-points. |