def test_auc_threshold(): """To compute rates: -> fpr: number of false positives / total number of negatives -> tpr: number of true positives / total number of positives In this example, consider the first threshold of 0.1, and consider everything higher than 0.1 as positives, and everything lower as negatives: fpr = 1 / 2 = 0.5 tpr = 1 Thus, if the max_fpr rate is 0.1, the tpr is 0, and if the max_fpr is 0.5, then the tpr is 1. So we get an auc of 0 for the 0.1 threshold, and 0.5 for the 0.5 threshold. For more details: https://en.wikipedia.org/wiki/Receiver_operating_characteristic """ y_pred = torch.tensor([0.1, 0.2, 0.3, 0.4]) y_true = torch.tensor([0, 1, 0, 1]) metric_test_case(y_pred, y_true, AUC(max_fpr=1.), sklearn.metrics.roc_auc_score(y_true, y_pred)) metric_test_case(y_pred, y_true, AUC(max_fpr=0.500001), 0.5) metric_test_case(y_pred, y_true, AUC(max_fpr=0.1), 0.5)
def test_auc_full(): """Test random score list.""" y_pred = np.random.randint(0, 10000, 100) y_true = np.random.randint(0, 2, 100) metric_test_case(y_pred, y_true, AUC(), sklearn.metrics.roc_auc_score(y_true, y_pred))