-
Notifications
You must be signed in to change notification settings - Fork 1
/
mter.py
64 lines (57 loc) · 1.49 KB
/
mter.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import cornac
from cornac.utils import cache
from cornac.models import MTER
from cornac.metrics import AUC, Recall, NDCG
from cornac.datasets import amazon_toy
from cornac.experiment import Experiment
from cornac.data.reader import Reader
from cornac.eval_methods import StratifiedSplit
from cornac.data.sentiment import SentimentModality
rating = amazon_toy.load_feedback(fmt="UIRT", reader=Reader(min_user_freq=10))
sentiment_data = amazon_toy.load_sentiment()
md = SentimentModality(data=sentiment_data)
eval_method = StratifiedSplit(
rating,
group_by="user",
chrono=True,
sentiment=md,
test_size=0.2,
val_size=0.16,
exclude_unknowns=True,
verbose=True,
)
model = MTER(
name="MTER",
n_user_factors=8,
n_item_factors=8,
n_aspect_factors=8,
n_opinion_factors=8,
n_bpr_samples=1000,
n_element_samples=50,
lambda_reg=0.1,
lambda_bpr=10,
max_iter=10000,
lr=0.5,
verbose=True,
)
n_items = eval_method.train_set.num_items
k_1 = int(n_items / 100)
k_5 = int(n_items * 5 / 100)
k_10 = int(n_items * 10 / 100)
cornac.Experiment(
eval_method=eval_method,
models=[model],
metrics=[
cornac.metrics.AUC(),
cornac.metrics.Recall(k=k_1),
cornac.metrics.Recall(k=k_5),
cornac.metrics.Recall(k=k_10),
cornac.metrics.NDCG(k=k_1),
cornac.metrics.NDCG(k=k_5),
cornac.metrics.NDCG(k=k_10),
],
show_validation=True,
save_dir="dist/toy/result",
verbose=True,
).run()