155 |
155 |
156 // recommendations(ratings_map, movies_map, "4") |
156 // recommendations(ratings_map, movies_map, "4") |
157 // => Nil (there are three ratings for this movie in ratings.csv but they are not positive) |
157 // => Nil (there are three ratings for this movie in ratings.csv but they are not positive) |
158 |
158 |
159 |
159 |
160 // If you want to calculate the recommendations for all movies, |
|
161 // then use this code (it will take a few seconds calculation time). |
|
162 |
160 |
163 //val all = for (name <- movie_names.map(_._1)) yield { |
161 // (7) Calculate the recommendations for all movies according to |
164 // recommendations(ratings_map, movies_map, name) |
162 // what the recommendations function in (6) produces (this |
165 //} |
163 // can take a few seconds). Put all recommendations into a list |
|
164 // (of strings) and count how often the strings occur in |
|
165 // this list. This produces a list of string-int pairs, |
|
166 // where the first component is the movie name and the second |
|
167 // is the number of how many times they were recommended. |
|
168 // Sort all the pairs according to the number |
|
169 // of times they were recommended (most recommended movie name |
|
170 // first). |
166 |
171 |
167 // helper functions |
172 def most_recommended(recs: Map[String, List[String]], |
168 //List().take(2) |
173 movs: Map[String, String]) : List[(String, Int)] = ??? |
169 //List(1).take(2) |
174 |
170 //List(1,2).take(2) |
175 |
171 //List(1,2,3).take(2) |
176 // testcase |
|
177 // |
|
178 //most_recommended(ratings_map, movies_map).take(3) |
|
179 // => |
|
180 // List((Matrix,698), |
|
181 // (Star Wars: Episode IV - A New Hope (1977),402), |
|
182 // (Jerry Maguire (1996),382)) |
|
183 |
172 |
184 |
173 |
185 |
174 } |
186 } |