From f2eb315f20195ea8939c585dd7215dc8c9abb187 Mon Sep 17 00:00:00 2001 From: sunnybest1990 Date: Wed, 2 Aug 2017 15:49:31 +0800 Subject: [PATCH] check length actual with len() not actual may have problem with numpy --- Python/ml_metrics/average_precision.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/ml_metrics/average_precision.py b/Python/ml_metrics/average_precision.py index e18297d..4e4f90a 100644 --- a/Python/ml_metrics/average_precision.py +++ b/Python/ml_metrics/average_precision.py @@ -33,7 +33,7 @@ def apk(actual, predicted, k=10): num_hits += 1.0 score += num_hits / (i+1.0) - if not actual: + if len(actual) == 0: return 0.0 return score / min(len(actual), k)