See the page on mean average precision at Kaggle

import spire.math.Rational
import axle.ml.RankedClassifierPerformance._

Examples (from benhamner/Metrics)

meanAveragePrecisionAtK[Int, Rational](List(1 until 5), List(1 until 5), 3)
// res0: spire.math.Rational = 1

// should be Rational.one
meanAveragePrecisionAtK[Int, Rational](List(List(1, 3, 4), List(1, 2, 4), List(1, 3)), List(1 until 6, 1 until 6, 1 until 6), 3)
// res2: spire.math.Rational = 37/54

// should be Rational(37, 54) aka 0.6851851851851851
meanAveragePrecisionAtK[Int, Rational](List(1 until 6, 1 until 6), List(List(6, 4, 7, 1, 2), List(1, 1, 1, 1, 1)), 5)
// res4: spire.math.Rational = 13/50

// should be Rational(13, 50)
meanAveragePrecisionAtK[Int, Rational](List(List(1, 3), List(1, 2, 3), List(1, 2, 3)), List(1 until 6, List(1, 1, 1), List(1, 2, 1)), 3)
// res6: spire.math.Rational = 11/18

// should be Rational(11, 18) aka 0.611111111111111