text_plain_output_1.png
import numpy as np

import pandas as pd

INPUT_PATH = '../input/'
childPref = pd.read_csv(INPUT_PATH + 'child_wishlist.csv', header=None).as_matrix()[:, 1:]
santaPref = pd.read_csv(INPUT_PATH + 'gift_goodkids.csv', header=None).as_matrix()[:, 1:]

numChildren = childPref.shape[0]
numGifts = santaPref.shape[0]
numGiftsPerChild = numChildren / numGifts
numTwins = 4000

print('creating child vs. gift value matrix...')
childPreferenceMatrix = -1 * np.ones((numChildren, numGifts), np.float32)
for childID in range(numChildren):
    for giftOrder, giftID in enumerate(childPref[childID, :]):
        childPreferenceMatrix[childID, giftID] = 2 * (10 - giftOrder)
santaPreferenceMatrix = -1 * np.ones((numChildren, numGifts), np.float32)
for giftID in range(numGifts):
    for childOrder, childID in enumerate(santaPref[giftID, :]):
        santaPreferenceMatrix[childID, giftID] = 2 * (1000 - childOrder)
child_vs_gift_matrix = childPreferenceMatrix / (20.0 * numChildren)
child_vs_gift_matrix += santaPreferenceMatrix / (2000000.0 * numGifts)
child_vs_gift_matrix = child_vs_gift_matrix.astype(np.float32)
del childPreferenceMatrix
del santaPreferenceMatrix