Datasets:

Modalities:
Text
Formats:
json
Languages:
Slovak
DOI:
Libraries:
Datasets
pandas
License:
File size: 2,088 Bytes
a8a2b54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pandas as pd


def count_map(actual_list, predicted_list, count_results):
    """
    Funtion for count MAP metric
    :param actual_list:  actual results from annotated datatest
    :param predicted_list: predicted results from searched engine
    :return: map value in question MAP value
    """

    # Initialization empty list for results
    questions = []
    k_stops = []
    frequencies = []
    mAPs = []

    # For every question
    for q, (actual, predicted) in enumerate(zip(actual_list, predicted_list), 1):
        k_stop = None  # initialization value who stop cycle for this question
        ap_sum = 0  # initialization sum AP on question
        count = 0  # count value k_stop

        # Loop throw values k
        for x, pred_value in enumerate(predicted[:count_results], 1):
            act_set = set(actual)
            pred_set = set(predicted[:x])
            precision_at_k = len(act_set & pred_set) / x

            if pred_value in actual:
                rel_k = 1
            else:
                rel_k = 0

            ap_sum += precision_at_k * rel_k

            # If we have found all the relevant values and we don't have k_stop yet, we stop
            if len(act_set) == ap_sum and k_stop is None:
                k_stop = x
                count += 1

        # If we haven't reached k_stop by 15, we set it to 15
        if k_stop is None:
            k_stop = count_results

        # Count mAP for question
        ap_q = ap_sum / len(actual)

        # Save results to list
        questions.append(q)
        k_stops.append(k_stop)
        frequencies.append(count)
        mAPs.append(round(ap_q, 2))

    # Create DataFrame from results
    df_results = pd.DataFrame({'Question': questions, 'k_stop': k_stops, 'Frequency': frequencies, 'mAP': mAPs})

    # Count total mAP
    total_mAP = round(df_results['mAP'].mean(), 2)

    print(f"MAP Metric for {count_results} is: {total_mAP}")

    k_stop_counts = df_results['k_stop'].value_counts()
    print(f"Count of K_stop \n{k_stop_counts}")

    return df_results, round(total_mAP,2)