Esempio n. 1
0
def convert_usertomatrix(userhistory, n_items):
	x = userhistory.groupby(['user_id']).apply(lambda r: binary_vector(n_items, list(r['item_idx']))).reset_index(name= 'items_onehot')
	user_idx = np.array(x['user_id']).astype(int)
	user_arr = stack_df(x['items_onehot'], (len(x), n_items))
	return user_idx, user_arr
Esempio n. 2
0
def convert_itemtomatrix(item_df, n_items):
	y = item_df.groupby(['item_rec']).apply(lambda r: create_vector(n_items, list(r['item_his']), list(r['score']))).reset_index(name= 'items_onehot')
	item_idx = np.array(y['item_rec']).astype(int)
	item_arr = stack_df(y['items_onehot'], (len(y), n_items))
	return item_idx, item_arr
Esempio n. 3
0
def convert_useraslist_toweightmatrix(userhistory_aslist, n_items):
	x = userhistory_aslist.groupby(['user_idx']).apply(lambda r: create_vector(n_items, list(r['items']), list(r['date_level']))).reset_index(name='items_onehot')
	user_idx = np.array(x['user_idx']).astype(int)
	user_arr = stack_df(x['items_onehot'], (len(x), n_items))
	return user_idx, user_arr