cws/main_cw02.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 25 Nov 2020 17:28:48 +0000
changeset 369 569aea2d052b
parent 356 d1046d9d3213
child 396 3ffe978a5664
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
268
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
     1
% !TEX program = xelatex
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
\documentclass{article}
39
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
     3
\usepackage{../style}
166
780c40aaad27 updated
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
     4
\usepackage{disclaimer}
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
     5
\usepackage{../langs}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
\begin{document}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    10
%% should ask to lower case the words.
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    11
356
d1046d9d3213 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 350
diff changeset
    12
\section*{Main Part 2 (Scala, 7 Marks)}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    14
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    15
\noindent
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    16
You are asked to implement a Scala program for recommending movies
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    17
according to a ratings list. This part is due on \cwSEVENa{} at 5pm.\bigskip
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 48
diff changeset
    18
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    19
\IMPORTANTNONE{}
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    20
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    21
\noindent
144
716042628398 updated
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    22
Also note that the running time of each part will be restricted to a
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    23
maximum of 30 seconds on my laptop.
39
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    24
166
780c40aaad27 updated
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    25
\DISCLAIMER{}
39
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    26
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    27
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    28
\subsection*{Reference Implementation}
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    29
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    30
Like the C++ part, the Scala part works like this: you push your files
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    31
to GitHub and receive (after sometimes a long delay) some automated
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    32
feedback. In the end we will take a snapshot of the submitted files
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    33
and apply an automated marking script to them.\medskip
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    34
268
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
    35
\noindent
306
Christian Urban <urbanc@in.tum.de>
parents: 301
diff changeset
    36
In addition, the Scala part comes with reference
Christian Urban <urbanc@in.tum.de>
parents: 301
diff changeset
    37
implementations in form of \texttt{jar}-files. This allows you to run
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    38
any test cases on your own computer. For example you can call Scala on
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    39
the command line with the option \texttt{-cp danube.jar} and then
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    40
query any function from the template file. Say you want to find out
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    41
what the function \texttt{} produces: for this you just need
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    42
to prefix it with the object name \texttt{CW7b}.  If you want to find out what
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    43
these functions produce for the list \texttt{List("a", "b", "b")},
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    44
you would type something like:
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    46
\begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    47
$ scala -cp danube.jar
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    48
scala> val ratings_url =
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    49
     | """https://nms.kcl.ac.uk/christian.urban/ratings.csv"""
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    50
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    51
scala> CW7b.get_csv_url(ratings_url)
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    52
val res0: List[String] = List(1,1,4 ...)
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    53
\end{lstlisting}%$
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    54
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    55
\subsection*{Hints}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    57
\noindent
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    58
Use \texttt{.split(",").toList} for splitting
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    59
strings according to commas (similarly for the newline character \mbox{$\backslash$\texttt{n}}),
301
c3b33c709696 updated
Christian Urban <urbanc@in.tum.de>
parents: 284
diff changeset
    60
\texttt{.getOrElse(..,..)} allows to query a Map, but also gives a
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    61
default value if the Map is not defined, a Map can be `updated' by
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    62
using \texttt{+}, \texttt{.contains} and \texttt{.filter} can test whether
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    63
an element is included in a list, and respectively filter out elements in a list,
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    64
\texttt{.sortBy(\_.\_2)} sorts a list of pairs according to the second
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    65
elements in the pairs---the sorting is done from smallest to highest,
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    66
\texttt{.take(n)} for taking some elements in a list (takes fewer if the list
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    67
contains less than \texttt{n} elements).
39
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    68
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    69
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    70
\newpage
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
356
d1046d9d3213 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 350
diff changeset
    73
\subsection*{Main Part 2 (7 Marks, file danube.scala)}
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    74
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    75
You are creating Danube.co.uk which you hope will be the next big thing
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    76
in online movie renting. You know that you can save money by
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    77
anticipating what movies people will rent; you will pass these savings
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    78
on to your users by offering a discount if they rent movies that
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    79
Danube.co.uk recommends.  
48
7a6a75ea9738 updated
Christian Urban <urbanc@in.tum.de>
parents: 46
diff changeset
    80
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    81
Your task is to generate \emph{two} movie recommendations for every
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    82
movie a user rents. To do this, you calculate what other
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    83
renters, who also watched this movie, suggest by giving positive ratings.
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    84
Of course, some suggestions are more popular than others. You need to find
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    85
the two most-frequently suggested movies. Return fewer recommendations,
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    86
if there are fewer movies suggested.
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    87
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    88
The calculations will be based on the small datasets which the research lab
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    89
GroupLens provides for education and development purposes.
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    90
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    91
\begin{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    92
\url{https://grouplens.org/datasets/movielens/}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    93
\end{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    94
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    95
\noindent
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    96
The slightly adapted CSV-files should be downloaded in your Scala
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    97
file from the URLs:
148
ead6089209ba updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
    98
ead6089209ba updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
    99
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   100
\begin{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   101
\begin{tabular}{ll}  
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   102
  \url{https://nms.kcl.ac.uk/christian.urban/ratings.csv} & (940 KByte)\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   103
  \url{https://nms.kcl.ac.uk/christian.urban/movies.csv}  & (280 KByte)\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   104
\end{tabular}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   105
\end{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   106
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   107
\noindent
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   108
The ratings.csv file is organised as userID, 
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   109
movieID, and rating (which is between 0 and 5, with \emph{positive} ratings
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   110
being 4 and 5). The file movie.csv is organised as
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   111
movieID and full movie name. Both files still contain the usual
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   112
CSV-file header (first line). In this part you are asked
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   113
to implement functions that process these files. If bandwidth
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   114
is an issue for you, download the files locally, but in the submitted
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   115
version use \texttt{Source.fromURL} instead of \texttt{Source.fromFile}.
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   116
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   117
\subsection*{Tasks}
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   118
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   119
\begin{itemize}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   120
\item[(1)] Implement the function \pcode{get_csv_url} which takes an
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   121
  URL-string as argument and requests the corresponding file. The two
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   122
  URLs of interest are \pcode{ratings_url} and \pcode{movies_url},
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   123
  which correspond to CSV-files mentioned above.  The function should
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   124
  return the CSV-file appropriately broken up into lines, and the
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   125
  first line should be dropped (that is omit the header of the CSV-file).
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   126
  The result is a list of strings (the lines in the file). In case
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   127
  the url does not produce a file, return the empty list.\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   128
  \mbox{}\hfill [1 Mark]
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   129
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   130
\item[(2)] Implement two functions that process the (broken up)
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   131
  CSV-files from (1). The \pcode{process_ratings} function filters out all
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   132
  ratings below 4 and returns a list of (userID, movieID) pairs. The
333
24bc76d97db2 updated
Christian Urban <urbanc@in.tum.de>
parents: 329
diff changeset
   133
  \pcode{process_movies} function returns a list of (movieID, title) pairs.
24bc76d97db2 updated
Christian Urban <urbanc@in.tum.de>
parents: 329
diff changeset
   134
  Note the input to these functions will be the output of the function
24bc76d97db2 updated
Christian Urban <urbanc@in.tum.de>
parents: 329
diff changeset
   135
  \pcode{get_csv_url}.\\
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   136
  \mbox{}\hfill [1 Mark]
268
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   137
%\end{itemize}  
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   138
%  
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   139
%
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   140
%\subsection*{Part 3 (4 Marks, file danube.scala)}
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   141
%
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   142
%\subsection*{Tasks}
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   143
%
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   144
%\begin{itemize}
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   145
\item[(3)] Implement a kind of grouping function that calculates a Map
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   146
  containing the userIDs and all the corresponding recommendations for
259
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents: 251
diff changeset
   147
  this user (list of movieIDs). This should be implemented in a
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents: 251
diff changeset
   148
  tail-recursive fashion using a Map as accumulator. This Map is set to
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   149
  \pcode{Map()} at the beginning of the calculation. For example
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   150
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   151
\begin{lstlisting}[numbers=none]
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   152
val lst = List(("1", "a"), ("1", "b"),
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   153
               ("2", "x"), ("3", "a"),
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   154
               ("2", "y"), ("3", "c"))
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   155
groupById(lst, Map())
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   156
\end{lstlisting}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   157
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   158
returns the ratings map
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   159
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   160
\begin{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   161
  \pcode{Map(1 -> List(b, a), 2 -> List(y, x), 3 -> List(c, a))}.
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   162
\end{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   163
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   164
\noindent
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   165
In which order the elements of the list are given is unimportant.\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   166
\mbox{}\hfill [1 Mark]
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   167
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   168
\item[(4)] Implement a function that takes a ratings map and a movieID
210
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 203
diff changeset
   169
  as arguments.  The function calculates all suggestions containing the
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 203
diff changeset
   170
  given movie in its recommendations. It returns a list of all these
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   171
  recommendations (each of them is a list and needs to have the given
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   172
  movie deleted, otherwise it might happen we recommend the same movie
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   173
  ``back''). For example for the Map from above and the movie
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   174
  \pcode{"y"} we obtain \pcode{List(List("x"))}, and for the movie
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   175
  \pcode{"a"} we get \pcode{List(List("b"), List("c"))}.\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   176
  \mbox{}\hfill [1 Mark]
148
ead6089209ba updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   177
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   178
\item[(5)] Implement a suggestions function which takes a ratings map
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   179
  and a movieID as arguments. It calculates all the recommended movies
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   180
  sorted according to the most frequently suggested movie(s) sorted
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   181
  first. This function returns \emph{all} suggested movieIDs as a list of
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   182
  strings.\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   183
  \mbox{}\hfill [1 Mark]
148
ead6089209ba updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   184
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   185
\item[(6)]  
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   186
  Implement then a recommendation function which generates a maximum
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   187
  of two most-suggested movies (as calculated above). But it returns
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   188
  the actual movie name, not the movieID. If fewer movies are recommended,
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   189
  then return fewer than two movie names.\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   190
  \mbox{}\hfill [1 Mark]
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   191
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   192
\item[(7)] Calculate the recommendations for all movies according to
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   193
 what the recommendations function in (6) produces (this
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   194
 can take a few seconds). Put all recommendations into a list 
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   195
 (of strings) and count how often the strings occur in
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   196
 this list. This produces a list of string-int pairs,
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   197
 where the first component is the movie name and the second
350
c5ad0e3f2a6d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 349
diff changeset
   198
 is the number of how many times the movie was recommended. 
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   199
 Sort all the pairs according to the number
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   200
 of times they were recommended (most recommended movie name 
350
c5ad0e3f2a6d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 349
diff changeset
   201
 first).\\
c5ad0e3f2a6d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 349
diff changeset
   202
 \mbox{}\hfill [1 Mark]
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   203
  
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   204
\end{itemize}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
268
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   206
\end{document} 
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
%%% Local Variables: 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
%%% mode: latex
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
%%% TeX-master: t
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
%%% End: 
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   212
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   213
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   214