-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrecommend.py
More file actions
47 lines (27 loc) · 1.68 KB
/
recommend.py
File metadata and controls
47 lines (27 loc) · 1.68 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from utils import *
from sklearn.metrics import mean_absolute_error
import pickle
train, test, max_user, max_work, mapping_work = get_data()
#pickle.dump(mapping_work, open('mapping_work.pkl', 'wb'))
#######################################################################
model = get_model_1(max_work, max_user)
history = model.fit([get_array(train["movieId"]), get_array(train["userId"])], get_array(train["rating"]), nb_epoch=10,
validation_split=0.2, verbose=0)
#model.save_weights("model_1.h5")
predictions = model.predict([get_array(test["movieId"]), get_array(test["userId"])])
test_performance = mean_absolute_error(test["rating"], predictions)
print(" Test Mae model 1 : %s " % test_performance)
#######################################################################
model = get_model_2(max_work, max_user)
history = model.fit([get_array(train["movieId"]), get_array(train["userId"])], get_array(train["rating"]), nb_epoch=10,
validation_split=0.2, verbose=0)
predictions = model.predict([get_array(test["movieId"]), get_array(test["userId"])])
test_performance = mean_absolute_error(test["rating"], predictions)
print(" Test Mae model 2 : %s " % test_performance)
#######################################################################
model = get_model_3(max_work, max_user)
history = model.fit([get_array(train["movieId"]), get_array(train["userId"])], get_array(train["rating"]), nb_epoch=10,
validation_split=0.2, verbose=0)
predictions = model.predict([get_array(test["movieId"]), get_array(test["userId"])])
test_performance = mean_absolute_error(test["rating"], predictions)
print(" Test Mae model 3 : %s " % test_performance)