def __init__(self, table=None, filename=''):
"""
table: the pandas DataFrame that records rankable objects competition
record
filename: the hdf5 filename that stores the DataFrame. The DataFrame
must be indexed by 'item_pair_rate'.
"""
if table is None:
table = pd.read_hdf(filename, "item_pair_rate")
table = table[['primary','secondary','rate1','rate2','weight']]
self.table = table
# itemid to index table
idx = self._extract_list(self.table)
self.itemlist = idx
temptable = table.iloc[:,:2].values
pair = np.fromfunction(np.vectorize(lambda i, j: idx[temptable[i,j]]),
temptable.shape)
pair = np.require(pair, dtype=np.int32)
self.pair = pair
评论列表
文章目录