-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathvebpr_example.py
More file actions
31 lines (27 loc) · 1.17 KB
/
vebpr_example.py
File metadata and controls
31 lines (27 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Note: This is a synthetic example purely for demonstrating the API usage.
# MovieLens ratings < 4 are mapped to 'views'. In reality, low ratings indicate negative
# preference rather than intermediate interest, which may cause VEBPR to underperform
# standard BPR here. For real performance gains, use sparse E-commerce datasets with true view logs.
import cornac
from cornac.data import PurchaseViewDataset
from cornac.datasets import movielens
from cornac.eval_methods import RatioSplit
from cornac.models import BPR, VEBPR
from cornac.metrics import NDCG, Recall
ml_100k = movielens.load_feedback()
purchase_data = [(u, i, 1.0) for u, i, r in ml_100k if r >= 4.0]
view_data = [(u, i, 1.0) for u, i, r in ml_100k if r < 4.0]
eval_method = RatioSplit(
data=purchase_data, test_size=0.2, seed=123, exclude_unknowns=True
)
eval_method.train_set = PurchaseViewDataset.attach_view(
eval_method.train_set, view_data
)
shared_params = dict(
k=50, max_iter=1000, learning_rate=0.01, lambda_reg=0.01, seed=123, verbose=True
)
cornac.Experiment(
eval_method=eval_method,
models=[BPR(**shared_params), VEBPR(alpha=0.5, **shared_params)],
metrics=[Recall(k=50), NDCG(k=50)],
).run()