-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
66 lines (61 loc) · 1.65 KB
/
example.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
65
66
from cornac.datasets import movielens
from cornac.eval_methods import RatioSplit
from cornac.experiment import Experiment_Explainers
from cornac.models import EMF, NEMF, ALS
from cornac.explainer import Exp_ALS, Exp_SU4EMF
from cornac.metrics_explainer import (
Metric_Exp_DIV as DIV,
Metric_Exp_PGF as PGF,
Metric_Exp_MEP as MEP,
Metric_Exp_EnDCG as EnDCG,
)
# Load MovieLens
data = movielens.load_feedback(variant="100K")
# Define an evaluation method to split feedback into train and test sets
ratio_split = RatioSplit(data=data, test_size=0.2, exclude_unknowns=False, verbose=True)
# initialize recommenders and explainers
emf = EMF(
k=10,
max_iter=500,
learning_rate=0.001,
lambda_reg=0.1,
explain_reg=0.01,
verbose=True,
seed=6,
num_threads=6,
early_stop=True,
)
nemf = NEMF(
k=10,
max_iter=500,
learning_rate=0.001,
lambda_reg=0.1,
explain_reg=0.01,
novel_reg=1,
verbose=True,
seed=6,
num_threads=6,
early_stop=True,
)
als = ALS(k=10, max_iter=500, lambda_reg=0.001, alpha=1, verbose=True, seed=6)
als_exp = Exp_ALS(rec_model=als, dataset=ratio_split.train_set)
emf_exp = Exp_SU4EMF(rec_model=emf, dataset=ratio_split.train_set)
nemf_exp = Exp_SU4EMF(rec_model=nemf, dataset=ratio_split.train_set)
# initialize metrics
fdiv = DIV()
pgf = PGF()
mep = MEP()
endcg = EnDCG()
# initialize experiment
models = [(emf, emf_exp), (als, als_exp), (nemf, nemf_exp)]
metrics = [fdiv, pgf, mep, endcg]
experiment = Experiment_Explainers(
eval_method=ratio_split,
models=models,
metrics=metrics,
distribution=False,
rec_k=10,
feature_k=10,
eval_train=True,
)
experiment.run()