statisticianinstilettos/recmetrics

mapk shouldn't require actual and predicted have the same length

mvonpohle opened this issue · 2 comments

This assertion check is incorrect. The actual parameter as used in _apk is expecting a list of true items and the predicted parameter is expecting a list of predicted items that can be true or false. See an example below where only A-C are true items and the prediction can be longer than the true list because it can contain false items.

if len(actual) != len(predicted):
raise AssertionError("Length mismatched")

true_items = ["A","B","C"]
prediction = ["A","Z","B","X"]
metrics.mapk(actual=true_items, predicted=prediction, k = 3)

Looks like you should be using _apk? For average precision, they can be of different length so there is no assertion

def _apk(actual: list, predicted: list, k=10) -> float:

The mapk is expecting both ground truth and predictions to be list of list.

def mapk(actual: List[list], predicted: List[list], k: int=10) -> float:

Ahh, yes. You're right, my bad.