Kaggle competition: Humpback Whale Identification
mapper_ord_1 = {'Novice': 1,
'Contributor': 2,
'Expert': 3,
'Master': 4,
'Grandmaster': 5}
traintest = pd.concat([train, test])
 train['ord_1_count'] = train['ord_1'].map(traintest['ord_1'].value_counts().to_dict())
 test['ord_1_count'] = test['ord_1'].map(traintest['ord_1'].value_counts().to_dict())
 mapper_ord_2 = {'Freezing': 1,
'Cold': 2,
'Warm': 3,
'Hot': 4,
'Boiling Hot': 5,
'Lava Hot': 6}
mapper_ord_3 = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8,
'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15}
mapper_ord_4 = {'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8,
'I': 9, 'J': 10, 'K': 11, 'L': 12, 'M': 13, 'N': 14, 'O': 15,
'P': 16, 'Q': 17, 'R': 18, 'S': 19, 'T': 20, 'U': 21, 'V': 22,
'W': 23, 'X': 24, 'Y': 25, 'Z': 26}
for col, mapper in zip(['ord_1', 'ord_2', 'ord_3', 'ord_4'], [mapper_ord_1, mapper_ord_2, mapper_ord_3, mapper_ord_4]):
train[col+'_oe'] = train[col].replace(mapper)
 test[col+'_oe'] = test[col].replace(mapper)
 train.drop(col, axis=1, inplace=True)
 test.drop(col, axis=1, inplace=True )<feature_engineering>
import pandas as pd
import csv
train['ord_5_oe1'] = train['ord_5'].apply(lambda x:(string.ascii_letters.find(x[0])+1))
test['ord_5_oe1'] = test['ord_5'].apply(lambda x:(string.ascii_letters.find(x[0])+1))
train['ord_5_oe2'] = train['ord_5'].apply(lambda x:(string.ascii_letters.find(x[1])+1))
test['ord_5_oe2'] = test['ord_5'].apply(lambda x:(string.ascii_letters.find(x[1])+1))
ord_5 = sorted(list(set(train['ord_5'].values)))
 ord_5 = dict(zip(ord_5, range(len(ord_5))))
train.loc[:, 'ord_5'] = train['ord_5'].apply(lambda x: ord_5[x] ).astype(float)
 test.loc[:, 'ord_5'] = test['ord_5'].apply(lambda x: ord_5[x] ).astype(float)
<data_type_conversions>
sub_files = [
".. /input/ensemble-0842/sub_simi_800.csv",
".. /input/ensemble-0842/sub_simi_805.csv",
".. /input/ensemble-0842/sub_ens_833.csv",
".. /input/ensemble-0842/sub_ens_824.csv",
".. /input/ensemble-0842/sub_tri_760.csv",
".. /input/ensemble-0842/sub_siam_822.csv",
]
sub_weight = [
0.800**2,
0.805**2,
0.833**2,
0.824**2,
0.76**2,
0.822**2,
]
<categorify><EOS> 
Hlabel = 'Image'
Htarget = 'Id'
npt = 6
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("submission_1.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()