Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions GMF.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Model,HR@10,NDCG@10
GMF,0.10438596492535189,0.4642449884038222
GMF,0.11101973684210527,0.4617882085473914
GMF,0.14029605263157896,0.47715529360269243
GMF,0.19747807022772337,0.49543382399960567
GMF,0.26403508766701345,0.5139023636516772
GMF,0.31968201759614445,0.5272904085485559
GMF,0.3660087718775398,0.5325772298009772
GMF,0.3904605263157895,0.5373425558993691
GMF,0.40657894736842104,0.5397488236427307
GMF,0.41677631578947366,0.5441246678954677
GMF,0.42379385954455323,0.5464331931189487
GMF,0.4264802631578947,0.5487803227023075
GMF,0.43125,0.5482266338248002
GMF,0.43262061398280294,0.5501784537967883
GMF,0.4337171052631579,0.5516256558267694
GMF,0.4342105263157895,0.5523644961808857
GMF,0.43486842105263157,0.5540454315511804
GMF,0.4351973684210526,0.5542220294475555
GMF,0.4355263157894737,0.5540746701391119
GMF,0.4356907894736842,0.5544112961543234
GMF,0.4363486842105263,0.5549225869931673
GMF,0.43700657894736844,0.5548475023947264
GMF,0.4375,0.5548983228834052
GMF,0.4381578947368421,0.5552136079261177
GMF,0.4384868421052632,0.5554311592327921
GMF,0.43914473684210525,0.5551701674335882
GMF,0.4393092105263158,0.5553232964716459
GMF,0.4393092105263158,0.5560040712356568
GMF,0.43914473684210525,0.5563049589332781
GMF,0.4394736842105263,0.5559233583902058
Binary file added HR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added HR2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
121 changes: 121 additions & 0 deletions MLP.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
Model,HR@10,NDCG@10
MLP_1,0.4456140351922888,0.5563795575970097
MLP_1,0.4457785088764994,0.5564770824030826
MLP_1,0.446600877297552,0.5562399412456311
MLP_1,0.4467653509817625,0.5564063160043013
MLP_1,0.4467653509817625,0.5562657506842362
MLP_1,0.4467653509817625,0.5565758792977584
MLP_1,0.4467653509817625,0.556453842238376
MLP_1,0.4469298246659731,0.556360315649133
MLP_1,0.4469298246659731,0.5561862173833345
MLP_1,0.4469298246659731,0.5561626892340811
MLP_1,0.4472587720343941,0.5559077836965259
MLP_1,0.4472587720343941,0.5560804370202517
MLP_1,0.4474232457186046,0.5559106456606011
MLP_1,0.4474232457186046,0.5559163915483575
MLP_1,0.4474232457186046,0.5559039843709845
MLP_1,0.4474232457186046,0.5559039843709845
MLP_1,0.4472587720343941,0.5559853478481895
MLP_1,0.4472587720343941,0.5559853478481895
MLP_1,0.4470942983501836,0.5560673594474792
MLP_1,0.4470942983501836,0.5560790739561382
MLP_1,0.4470942983501836,0.5561221430176183
MLP_1,0.4470942983501836,0.5561317745007966
MLP_1,0.4470942983501836,0.5562705221929048
MLP_1,0.4470942983501836,0.5562705221929048
MLP_1,0.4470942983501836,0.5562705221929048
MLP_1,0.4470942983501836,0.5562502522217599
MLP_1,0.4470942983501836,0.5562398465056169
MLP_1,0.4470942983501836,0.5562398465056169
MLP_1,0.4470942983501836,0.5562398465056169
MLP_1,0.4470942983501836,0.5562398465056169
MLP_2,0.4472587720343941,0.5563064763420507
MLP_2,0.4457785088764994,0.5575754720913736
MLP_2,0.4462719299291309,0.5570910089894345
MLP_2,0.4461074562449204,0.5576410864528857
MLP_2,0.4461074562449204,0.5573103142412086
MLP_2,0.4462719299291309,0.5572376693549909
MLP_2,0.446600877297552,0.5569262739859129
MLP_2,0.4464364036133414,0.5570037543773652
MLP_2,0.446600877297552,0.5569311258039976
MLP_2,0.446600877297552,0.5568064805708434
MLP_2,0.4467653509817625,0.5566659202701167
MLP_2,0.4467653509817625,0.5566939865287982
MLP_2,0.4467653509817625,0.5565541414838088
MLP_2,0.4469298246659731,0.5565257856720373
MLP_2,0.4469298246659731,0.5565587376293383
MLP_2,0.4469298246659731,0.5565587376293383
MLP_2,0.4467653509817625,0.556490253147326
MLP_2,0.4467653509817625,0.5564798474311828
MLP_2,0.4467653509817625,0.5564798474311828
MLP_2,0.4467653509817625,0.5564752428155196
MLP_2,0.4467653509817625,0.5564752428155196
MLP_2,0.4467653509817625,0.5564752428155196
MLP_2,0.4467653509817625,0.5564752428155196
MLP_2,0.4467653509817625,0.5564752428155196
MLP_2,0.4469298246659731,0.5563749978416844
MLP_2,0.4469298246659731,0.5563749978416844
MLP_2,0.4469298246659731,0.5563749978416844
MLP_2,0.4469298246659731,0.5563749978416844
MLP_2,0.4469298246659731,0.5563806251475686
MLP_2,0.4469298246659731,0.5564236942090486
MLP_3,0.4462719299291309,0.5576446759073358
MLP_3,0.4470942983501836,0.5568542784766147
MLP_3,0.446600877297552,0.5570903640044363
MLP_3,0.446600877297552,0.5570436901167819
MLP_3,0.446600877297552,0.5570418862920058
MLP_3,0.4464364036133414,0.5571527095217453
MLP_3,0.4464364036133414,0.5571428556191294
MLP_3,0.4464364036133414,0.5571638640604522
MLP_3,0.446600877297552,0.5570707584682264
MLP_3,0.446600877297552,0.5569233536720276
MLP_3,0.446600877297552,0.5569330306429612
MLP_3,0.4464364036133414,0.5569386077554602
MLP_3,0.4467653509817625,0.5568149507045745
MLP_3,0.4469298246659731,0.5567513095705132
MLP_3,0.4470942983501836,0.5566009358355873
MLP_3,0.4470942983501836,0.556592909913314
MLP_3,0.4470942983501836,0.5565968707988137
MLP_3,0.4469298246659731,0.5567070226920279
MLP_3,0.4469298246659731,0.5564473591352764
MLP_3,0.4469298246659731,0.5564430180348848
MLP_3,0.4469298246659731,0.5564430180348848
MLP_3,0.4469298246659731,0.5564326123187416
MLP_3,0.4469298246659731,0.5564280077030784
MLP_3,0.4469298246659731,0.5564280077030784
MLP_3,0.4469298246659731,0.5564280077030784
MLP_3,0.4469298246659731,0.5564280077030784
MLP_3,0.4469298246659731,0.5564131272466559
MLP_3,0.4469298246659731,0.5564131272466559
MLP_3,0.4469298246659731,0.5564131272466559
MLP_3,0.4469298246659731,0.5564131272466559
MLP_4,0.4472587720343941,0.5573230254022699
MLP_4,0.4470942983501836,0.5573333850032405
MLP_4,0.4470942983501836,0.5567386153497194
MLP_4,0.4470942983501836,0.556657655301847
MLP_4,0.446600877297552,0.5569917998815838
MLP_4,0.4464364036133414,0.5571311307580847
MLP_4,0.446600877297552,0.5570085315327895
MLP_4,0.4467653509817625,0.5569276586959236
MLP_4,0.446600877297552,0.5569460915891747
MLP_4,0.446600877297552,0.5570349752902984
MLP_4,0.446600877297552,0.5570168303815942
MLP_4,0.446600877297552,0.5571099052303716
MLP_4,0.446600877297552,0.5571299559191654
MLP_4,0.446600877297552,0.5571299559191654
MLP_4,0.4467653509817625,0.5570654508314634
MLP_4,0.4467653509817625,0.5569313817902615
MLP_4,0.4467653509817625,0.5567553068462171
MLP_4,0.4467653509817625,0.5567553068462171
MLP_4,0.4470942983501836,0.5565695781456796
MLP_4,0.4469298246659731,0.5566454724261635
MLP_4,0.4469298246659731,0.5566374465038902
MLP_4,0.4469298246659731,0.5566310016732466
MLP_4,0.4469298246659731,0.5566263970575834
MLP_4,0.4469298246659731,0.5565298507088109
MLP_4,0.4469298246659731,0.5565255096084193
MLP_4,0.4469298246659731,0.5565255096084193
MLP_4,0.4469298246659731,0.5565102596031992
MLP_4,0.4469298246659731,0.5563849386415983
MLP_4,0.4469298246659731,0.5563700581851758
MLP_4,0.4469298246659731,0.5563700581851758
Binary file added NDCG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added NDCG2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions NeuMF.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Model,HR@10,NDCG@10
NeuMF,0.4447916667712362,0.5538063309694591
NeuMF,0.4459429825607099,0.5587665598643453
NeuMF,0.44544956150807835,0.559753398832522
NeuMF,0.4452850878238678,0.560041973779076
NeuMF,0.446600877297552,0.558251712824169
NeuMF,0.44627192992913095,0.5578570930581344
NeuMF,0.4457785088764994,0.5586960654509695
NeuMF,0.44610745624492043,0.5584603849210237
NeuMF,0.4459429825607099,0.5583915290079619
NeuMF,0.4459429825607099,0.5577109474884836
NeuMF,0.44643640361334147,0.5573945196051346
NeuMF,0.446600877297552,0.5573740720748901
NeuMF,0.446600877297552,0.5575544570621691
NeuMF,0.44643640361334147,0.5576567863163195
NeuMF,0.4467653509817625,0.5572417202748751
NeuMF,0.44643640361334147,0.5573038016494952
NeuMF,0.44627192992913095,0.5573519320864426
NeuMF,0.44627192992913095,0.5573318202244608
NeuMF,0.446600877297552,0.5572456243791079
NeuMF,0.446600877297552,0.5572540160856749
NeuMF,0.44643640361334147,0.5572758991467325
NeuMF,0.44627192992913095,0.5576106011867523
NeuMF,0.44627192992913095,0.5577009856700897
NeuMF,0.44643640361334147,0.5576980418280552
NeuMF,0.44610745624492043,0.5577347836996379
NeuMF,0.44610745624492043,0.5576465813737167
NeuMF,0.44643640361334147,0.557455523390519
NeuMF,0.44643640361334147,0.557432362280394
NeuMF,0.44643640361334147,0.5573960552090093
NeuMF,0.44643640361334147,0.5575231548986936
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# STA326 - Assignment 3

## Overview
Expand Down
32 changes: 32 additions & 0 deletions evaluation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import numpy as np
import torch
import math

def evaluate(model, test_loader, negative_loader, top_k=10):
model.eval()
HR_list = []
NDCG_list = []

for (user_ids, pos_item_ids, _), (neg_user_ids, _, neg_item_ids) in zip(test_loader, negative_loader):
items = torch.cat([pos_item_ids.unsqueeze(1), neg_item_ids], dim=1)
user_ids = user_ids.unsqueeze(1).expand(-1, items.size(1))

user_ids = user_ids.reshape(-1)
item_ids = items.reshape(-1)
predictions = model(user_ids, item_ids).squeeze()
predictions = predictions.reshape(-1, 100)
_, indices = torch.topk(predictions, k=top_k, dim=1)
recommended_items = items.gather(1, indices)

HR = (recommended_items == pos_item_ids.unsqueeze(1)).any(dim=1).float()
HR_list.append(HR.mean().item())

relevant = (recommended_items == pos_item_ids.unsqueeze(1))
rank = relevant.nonzero(as_tuple=True)[1]
NDCG = (1 / torch.log2(rank.float() + 2)).mean().item()
NDCG_list.append(NDCG)

mean_HR = np.mean(HR_list)
mean_NDCG = np.mean(NDCG_list)

return mean_HR, mean_NDCG
Loading