To wrap up MP2 we'll use the preference data that we can access to identify relationships between difference restaurants. This will lead us in the direction of being able to make recommendations.
Today's lesson is short and sweet. Good luck wrapping up MP2!
At this point you've moved the restaurant preferences data to the client, and so now it's time to use it to identify relationships between restaurants! Let's briefly review what you need to do.
As a more complete description of your task, you should complete the
RelatedRestaurants as follows.
You should provide a single constructor accepting a
List<Restaurant> and a
List<Preference>, in that order.
Your class should also provide a method
getRelated that takes a
String containing a restaurant ID and returns a
Keys in the map should be IDs of restaurants that are related to the passed restaurant.
The values in the map should reflect the strength of the relationship.
Two restaurants are related if they appear in the same user's list of restaurant preferences. For example, if I like both Thara Thai and Black Dog, then those two restaurants are related. The strength of the relationship measures how many times two restaurants appear in the same list. So, if Colleen also likes Thara Thai, Black Dog, and Sakanaya, then the strength of the relationship between Thara Thai and Black Dog is 2 but between Sakanaya and Black Dog only 1. (Note that, while we're using restaurant names here, you'll be working with their unique IDs.)
A few important notes.
Mapfor all restaurant IDs in the passed
List<Restaurant>. So if a restaurant is not related to any others, or is not a valid restaurant ID, you should still return an empty
List<Restaurant>. You should ignore these invalid IDs and not include them in your map as keys in either the top-level map or in the secondary maps.
Preferencemodel! Nothing here will work until you do. Remember that you will need an empty constructor.
Our suggestion is that you do most of the work in the constructor, which should build a
Map<String, Map<String, Integer>> that is then used by
getRelated, which will be simple.
The assumption behind this algorithm is that a user's restaurant preferences are themselves related, and can be used in this way to generate recommendations. When you are done you may want to examine the output of this approach and see if you think that it is valid or not. Admittedly, this is a fairly small data set to train it on.
As a reminder, on lessons where we focus on the machine project we will not assign a homework problem! However, the lesson will usually focus on helping you complete a particular part of the MP test suite, and so we encourage you to spend time on that in lieu of a homework problem.