-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsuggest.py
43 lines (32 loc) · 832 Bytes
/
suggest.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
# -*-
import pickle
import numpy
import loader
def dictSort(d):
""" returns a dictionary sorted by keys """
our_list = d.items()
our_list.sort()
k = {}
for item in our_list:
k[item[0]] = item[1]
return k
id = 26
pkl_file = open('factorization.pkl', 'rb')
data = pickle.load(pkl_file)
pkl_file.close()
A = data['A'].T
B = data['B'].T
movie = A[id, :]
movie /= numpy.linalg.norm(movie)
print movie.shape
titles = loader.MovieLoader().loadTitles()
values = numpy.zeros((A.shape[0], 2))
for m in range(A.shape[0]):
other = A[m, :]
other /= numpy.linalg.norm(other)
distance = 1.0 - numpy.inner(movie , other)[0, 0]
values[m, 0] = numpy.abs(distance)
values[m, 1] = m
sortIndex = numpy.argsort(values[:, 0])
for movie in values[sortIndex[0:10], 1]:
print titles[movie]