Databases Reference
In-Depth Information
Exercise: Build Your Own Recommendation
System
In
Chapter 6
, we did some exploratory data analysis on the GetGlue
dataset. Now's your opportunity to build a recommendation system
with that dataset. The following code isn't for GetGlue, but it is Matt's
code to illustrate implementing a recommendation system on a rela‐
tively small dataset. Your challenge is to adjust it to work with the
GetGlue data.
Sample Code in Python
import
math
,
numpy
pu
=
[[(
0
,
0
,
1
),(
0
,
1
,
22
),(
0
,
2
,
1
),(
0
,
3
,
1
),(
0
,
5
,
0
)],[(
1
,
0
,
1
),
(
1
,
1
,
32
),(
1
,
2
,
0
),(
1
,
3
,
0
),(
1
,
4
,
1
),(
1
,
5
,
0
)],[(
2
,
0
,
0
),(
2
,
1
,
18
),
(
2
,
2
,
1
),(
2
,
3
,
1
),(
2
,
4
,
0
),(
2
,
5
,
1
)],[(
3
,
0
,
1
),(
3
,
1
,
40
),(
3
,
2
,
1
),
(
3
,
3
,
0
),(
3
,
4
,
0
),(
3
,
5
,
1
)],[(
4
,
0
,
0
),(
4
,
1
,
40
),(
4
,
2
,
0
),(
4
,
4
,
1
),
(
4
,
5
,
0
)],[(
5
,
0
,
0
),(
5
,
1
,
25
),(
5
,
2
,
1
),(
5
,
3
,
1
),(
5
,
4
,
1
)]]
pv
=
[[(
0
,
0
,
1
),(
0
,
1
,
1
),(
0
,
2
,
0
),(
0
,
3
,
1
),(
0
,
4
,
0
),(
0
,
5
,
0
)],
[(
1
,
0
,
22
),(
1
,
1
,
32
),(
1
,
2
,
18
),(
1
,
3
,
40
),(
1
,
4
,
40
),(
1
,
5
,
25
)],
[(
2
,
0
,
1
),(
2
,
1
,
0
),(
2
,
2
,
1
),(
2
,
3
,
1
),(
2
,
4
,
0
),(
2
,
5
,
1
)],[(
3
,
0
,
1
),
(
3
,
1
,
0
),(
3
,
2
,
1
),(
3
,
3
,
0
),(
3
,
5
,
1
)],[(
4
,
1
,
1
),(
4
,
2
,
0
),(
4
,
3
,
0
),
(
4
,
4
,
1
),(
4
,
5
,
1
)],[(
5
,
0
,
0
),(
5
,
1
,
0
),(
5
,
2
,
1
),(
5
,
3
,
1
),(
5
,
4
,
0
)]]
V
=
numpy
.
mat
([[
0.15968384
,
0.9441198
,
0.83651085
],
[
0.73573009
,
0.24906915
,
0.85338239
],
[
0.25605814
,
0.6990532
,
0.50900407
],
[
0.2405843
,
0.31848888
,
0.60233653
],
[
0.24237479
,
0.15293281
,
0.22240255
],
[
0.03943766
,
0.19287528
,
0.95094265
]])
print
V
U
=
numpy
.
mat
(
numpy
.
zeros
([
6
,
3
]))
L
=
0.03
for
iter
in
xrange
(
5
):
print
"
\n
----- ITER
%s
-----"
%
(
iter
+
1
)
print
"U"
urs
=
[]
for
uset
in
pu
:
vo
=
[]
pvo
=
[]