AP@k (average precision)

AP@k (average precision)#

This metric is also counted for each object individually. So for \(j\)-th object it’ll take following formula:

\[AP_j@k=\frac{1}{N_j} \sum_{t=1}^k precision_j@t*r_{tj}\]

Where \(N_j=\sum_{i}^k r_{ij}\) - number of relevant items for \(j\)-th object in \(k\) best according to the model. We take \(k\) best elements and try to compute \(precision@t\) for each \(t=\overline{1,k}\). We add to the numerator only those precisions that correspond to the relevant values - in irrelevant cases \(r_{tj}=0\) will remove the corresponding \(precision@t\).

import pandas as pd

from IPython.display import HTML, Latex, Markdown

R_frame = pd.read_parquet("example.parquet")

Consider specific#

\(t\)

\(r_{i_t}\)

\(precision@t\)

\(precision@t \times r_{i_t}\)

1

1

1.0

1.0

2

0

0.5

0.0

3

0

0.33

0.0

4

1

0.5

0.5

5

1

0.6

0.6

6

0

0.5

0.0

7

1

-

-

8

1

-

-

9

0

-

-

10

0

-

-