Implement two ranking metrics for a list of recommended item ids and a set of relevant ones:
average_precision_at_k(recommended, relevant, k): the mean of precision@i at each rank i <= k where a relevant item appears, divided by min(len(relevant), k) (0 if nothing is relevant)ndcg_at_k(recommended, gains, k): gains maps item to graded relevance. , normalised by the DCG of the ideal ordering of all items in gains. Return 0 if the ideal DCG is 0.