File tree 1 file changed +7
-2
lines changed
1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change 10
10
# print(tmp)
11
11
12
12
from pyspark .mllib .recommendation import ALS , MatrixFactorizationModel , Rating
13
+ import os
13
14
14
15
# load in the data
16
+ < << << << HEAD
15
17
data = sc .textFile ("../large_files/movielens-20m-dataset/small_rating.csv" )
18
+ == == == =
19
+ data = sc .textFile (os .path .expanduser ('~' ) + "/Code/machine_learning_examples/large_files/movielens-20m-dataset/small_rating.csv" )
20
+ > >> >> >> f6f97af5e368bb1343243049d44f0a12635cfa38
16
21
17
22
# filter out header
18
23
header = data .first () #extract header
42
47
# joins on first item: (user_id, movie_id)
43
48
# each row of result is: ((user_id, movie_id), (rating, prediction))
44
49
mse = ratesAndPreds .map (lambda r : (r [1 ][0 ] - r [1 ][1 ])** 2 ).mean ()
45
- print ("train mse:" , mse )
50
+ print ("train mse: %s" % mse )
46
51
47
52
48
53
# test
49
54
x = test .map (lambda p : (p [0 ], p [1 ]))
50
55
p = model .predictAll (x ).map (lambda r : ((r [0 ], r [1 ]), r [2 ]))
51
56
ratesAndPreds = test .map (lambda r : ((r [0 ], r [1 ]), r [2 ])).join (p )
52
57
mse = ratesAndPreds .map (lambda r : (r [1 ][0 ] - r [1 ][1 ])** 2 ).mean ()
53
- print ("test mse:" , mse )
58
+ print ("test mse: %s" % mse )
You can’t perform that action at this time.
0 commit comments