From e64e281b6377e715642d35ae664761720358335d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Wed, 14 May 2025 13:15:33 +0200 Subject: [PATCH] Return AUC 0.5 if nPos==0 || nNeg==0 --- src/main/RocAuc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/RocAuc.cpp b/src/main/RocAuc.cpp index 03a1c31..c41d986 100644 --- a/src/main/RocAuc.cpp +++ b/src/main/RocAuc.cpp @@ -4,7 +4,7 @@ #include #include "RocAuc.h" namespace platform { - + double RocAuc::compute(const torch::Tensor& y_proba, const torch::Tensor& labels) { size_t nClasses = y_proba.size(1); @@ -48,6 +48,7 @@ namespace platform { double tp = 0, fp = 0; double totalPos = std::count(y_test.begin(), y_test.end(), classIdx); double totalNeg = nSamples - totalPos; + if (totalPos == 0 || totalNeg == 0) return 0.5; // neutral AUC for (const auto& [score, label] : scoresAndLabels) { if (label == 1) {