-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparinglossfunctions.py
69 lines (43 loc) · 1.82 KB
/
comparinglossfunctions.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
67
68
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from lightfm.datasets import fetch_movielens
from lightfm import LightFM
from lightfm.evaluation import auc_score
#fetch data and format it
data = fetch_movielens()
train,test = data['train'], data['test']
#print testing and training data in string representation
print(repr(data['train']))
print(repr(data['test']))
#create models
alpha = 1e-05
epochs = 60
num_components = 32
warp_model = LightFM(loss='warp', no_components=num_components, max_sampled=200 , user_alpha=alpha, item_alpha=alpha)
bpr_model = LightFM(loss='bpr', no_components=num_components, max_sampled=200 , user_alpha=alpha, item_alpha=alpha)
warpkos_model = LightFM(loss='warp-kos', no_components=num_components, max_sampled=200 , user_alpha=alpha, item_alpha=alpha)
logistic_model = LightFM(loss='logistic', no_components=num_components, max_sampled=200 , user_alpha=alpha, item_alpha=alpha)
warp_auc = []
bpr_auc = []
warpkos_auc = []
logistic_auc = []
for epoch in range(epochs):
warp_model.fit_partial(train, epochs=1)
warp_auc.append(auc_score(warp_model,test,train_interactions=train).mean())
for epoch in range(epochs):
bpr_model.fit_partial(train, epochs=1)
bpr_auc.append(auc_score(bpr_model,test,train_interactions=train).mean())
for epoch in range(epochs):
warpkos_model.fit_partial(train, epochs=1)
warpkos_auc.append(auc_score(warpkos_model,test,train_interactions=train).mean())
for epoch in range(epochs):
logistic_model.fit_partial(train, epochs=1)
logistic_auc.append(auc_score(logistic_model,test,train_interactions=train).mean())
x= np.arange(epochs)
plt.plot(x,np.array(warp_auc))
plt.plot(x,np.array(bpr_auc))
plt.plot(x,np.array(warpkos_auc))
plt.plot(x,np.array(logistic_auc))
plt.legend(['WARP AUC','BPR AUC','WARP-KOS AUC','LOGISTIC AUC'], loc='upper right')
plt.show()