Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Python/ml_metrics/average_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def apk(actual, predicted, k=10):
The average precision at k over the input lists

"""
if not actual:
return 0.0

if len(predicted)>k:
predicted = predicted[:k]

Expand All @@ -33,9 +36,6 @@ def apk(actual, predicted, k=10):
num_hits += 1.0
score += num_hits / (i+1.0)

if not actual:
return 0.0

return score / min(len(actual), k)

def mapk(actual, predicted, k=10):
Expand Down