Hi,
It is me again. Very appreciate the codes, it helps me a lot in understanding the paper. However, one minor thing, with the Gpop as the baseline model of the paper, I have managed to calculate the global similarity with (sumBui over users)/(sumBu over users). However, for the prediction and evaluation of the method, I got it all wrong. Could you have a look at those code and please give me some advice, suggestions?
def GPopMat(df_train, n_items):
'''
Calculate the user popularity matrix with the given recency window
'''
BUCount = df_train.groupby(['UID'])['order'].max().reset_index(name='Bu')
BUICount = df_train.groupby(['UID','PID'])['BID'].count().reset_index(name='Bui')
n_users = df_train.UID.unique().shape[0]
tmp = pd.merge(BUICount, BUCount, on='UID')
tmp['piUI'] = tmp['Bui']/tmp['Bu']
table = pd.pivot_table(tmp, values=['Bui','Bu'], index=['PID'], aggfunc=np.sum)
tmp2 = table.reset_index()
tmp2.columns = ['item', 'sumBUi', 'sumBU']
tmp2['globalPopularity'] = tmp2['sumBUi'] / tmp2['sumBU']
tmp2['UID'] = tmp['UID']
tmp2['PID'] = tmp['PID']
df_Gpop = tmp2[['PID','globalPopularity']]
del tmp2
del tmp
GPop_mat = sparse.coo_matrix((df_Gpop.globalPopularity.values, (df_Gpop.PID.values)), shape=(n_items))
#del df_Gpop
return sparse.csr_matrix(GPop_mat)
Gpop_mat.shape
prediction
score, pred = prediction(Gpop_mat.toarray(), k=5)
test_ndcg, dev_ndcg = evaluation(score, pred, test_set, dev_set, k=5)
print("test score:",test_ndcg,"\n dev score:",dev_ndcg)
del score,pred
Thanks so much again and have a very nice day!
Best,
Diep