Kaggle competition: Humpback Whale Identification
<SOS> metric: MAP@{K} Kaggle data source: humpback-whale-identification<train_model>
sub_files = ['.. /input/whale-ensemble/ensemble/0657.csv',
'.. /input/whale-ensemble/ensemble/0685.csv',
'.. /input/ensembling-m14-0-748/sub_ens.csv']
sub_weight = [0.657**2,
0.685**2,
0.748**2]
<prepare_x_and_y><EOS> 
Hlabel = 'Image'
Htarget = 'Id'
npt = 5
place_weights = {}
for i in range(npt):
place_weights[i] =(1 /(i + 1))
print(place_weights)
 lg = len(sub_files)
 sub = [None]*lg
for i, file in enumerate(sub_files):
print("Reading {}: w={} - {}".format(i, sub_weight[i], file))
reader = csv.DictReader(open(file,"r"))
sub[i] = sorted(reader, key=lambda d: str(d[Hlabel]))
out = open("submit_v8.csv", "w", newline='')
 writer = csv.writer(out)
 writer.writerow([Hlabel,Htarget])
 for p, row in enumerate(sub[0]):
target_weight = {}
for s in range(lg):
row1 = sub[s][p]
for ind, trgt in enumerate(row1[Htarget].split(' ')) :
target_weight[trgt] = target_weight.get(trgt,0)+(place_weights[ind]*sub_weight[s])
 tops_trgt = sorted(target_weight, key=target_weight.get, reverse=True)[:npt]
writer.writerow([row1[Hlabel], " ".join(tops_trgt)])
 out.close()