import numpy as np

def apk(actual, predicted, k=10):
    if len(predicted) > k:
        predicted = predicted[:k]

    score = 0.0
    num_hits = 0.0

    for i, p in enumerate(predicted):
        if p in actual and p not in predicted[:i]:
            num_hits += 1.0
            score += num_hits / (i+1.0)

    if not actual:
        return 0.0

    return score / min(len(actual), k)

def mapk(actual, predicted, k=10):
    return np.mean([apk(a, p, k) for a, p in zip(actual, predicted)])

# Example data
data = [
    [4814, 4814, 6010, 6011, 4814, 6011, 6011, 4814, 6011, 6011, 4814, 6011, 4814, 4814, 6011, 6011, 4814, 4814, 6011, 6011, 6011, 4814, 4814, 6011, 6011, 6011, 6011, 4814, 4814, 6011, 6011, 6011, 6011, 4814, 6011, 4814, 4814, 4814, 4814, 4814, 6011, 6011, 4814],
    [6011, 6011, 6011, 6011, 6011, 6011, 6011, 4814, 4814, 4814, 4814, 4814, 4814, 6011, 4829, 4814, 6011, 4814, 6011, 4814, 4814, 6010, 6011, 4814, 6010, 4814, 4814, 4814, 4814, 4814, 4814, 4814, 5541, 6011, 4814, 4814, 4814, 4814, 4814, 4814, 5732, 6011, 4814, 4814, 4814],
    [8021, 6011, 6011, 6010, 4829, 4814, 6011, 6011, 6011, 6011, 5719, 5331, 4814, 6010, 4829, 4829, 6010, 5411, 5211, 8999, 4814, 5814, 5814, 5814, 5814, 5814, 5814, 5331, 5814, 5331, 6010, 4814, 5814, 5814, 5814, 4829, 6010, 5814, 5814, 5641, 5641, 4511, 5331],
    [4814, 6011, 4814, 4814, 4814, 6011, 6011, 5691, 5691, 5411, 5411, 5411, 4814, 5411, 4814, 4814, 4814, 4814, 5411, 5411, 5814, 5411, 5411, 5411, 6011, 6011, 4814, 4814, 4814, 6011, 4814, 4814, 5411, 5411, 6011, 4814, 5411, 4814, 4814],
    [4814, 4814, 4814, 4814, 4814, 4814, 5946, 4814, 4814, 6011, 4814, 4814, 6010, 5411, 5499, 5411, 8021, 6011, 5912, 6011, 4829, 4814, 5977, 6011, 6011, 6011, 5499, 5411, 5999, 5411, 5411, 4814, 4814, 4814, 4814, 6011, 6011, 6011, 5411, 5691, 4814, 5912, 4814, 4814]
]

target = [
    [4814, 4814, 4814, 4814, 5411, 4814, 4814, 4814, 4814, 4814],
    [4814, 6011, 4814, 6011, 4814, 4814, 6011, 4814, 6011, 4814],
    [6011, 6011, 6010, 4829, 4829, 6010, 6011, 6011, 4814, 6011],
    [6011, 6011, 6010, 6011, 6011, 4814, 4814, 6011, 4814, 4814],
    [5499, 6011, 4814, 4829, 5200, 5411, 5499, 5912, 5411, 5912]
]

# Predict the target based on the data
predicted = [] # Store the predicted targets

# Loop through each data sequence
for d in data:
    # For each data sequence, predict the target based on the most common element in Data
    predicted_sequence = [np.argmax(np.bincount(d))] * 10
    predicted.append(predicted_sequence)

# Calculate the mapk score
score = mapk(target, predicted)

print(“MAPK Score:”, score)

The error is ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[17], line 7
      4 # Loop through each data sequence
      5 for d in df_train:
      6     # For each data sequence, predict the target based on the most common element in Data
----> 7     predicted_sequence = [np.argmax(np.bincount(d))] * 10
      8     predicted.append(predicted_sequence)
     10 # Calculate the mapk score

File <__array_function__ internals>:200, in bincount(*args, **kwargs)

ValueError: object of too small depth for desired array