Machine Learning with Spark - Second Edition
by Rajdeep Dua, Brian O'Neill, Stephen Boesch, Manpreet Singh Ghotra, Nick Pentreath
MAP
As we did for MSE and RMSE, we can compute ranking-based evaluation metrics using MLlib's RankingMetrics class. Similarly, to our own average precision function, we will need to pass in an RDD of key-value pairs, where the key is Array of predicted item IDs for a user, while the value is an array of actual item IDs.
The implementation of the average precision at the K function in RankingMetrics is slightly different from ours, so we will get different results. However, the computation of the overall Mean Average Precision (MAP, which does not use a threshold at K) is the same as our function if we select K to be very high (say, at least as high as the number of items in our item set).
First, we will calculate MAP using RankingMetrics ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access