The simplest recommender doesn't look at who the customer is. It offers the shop's most popular products and skips the ones the customer already has. It is rarely the best, but it is the baseline: a smarter recommender has to beat it to be worth its code.
Count customers, not lines: a customer who bought the Mug three times should count once. groupby(column)[other].nunique() gives back, for each group, how many different values the other column has. For example, how many different products each customer bought:
per_customer = paid.groupby("customer_id")["product"].nunique()
sort_values(ascending=False) gives back the same Series sorted from the largest number down. Its .index holds the labels, here the product names, in that order. Walk down that index and skip what the customer owns (the given bought(customer_id) gives back their products as a list). Then picks[:3] keeps the first three.
Your program must print this. After it, the check runs your recommender for all 300 customers and prints how often each product comes up.
product Gift card 197 Lamp 116 Plant 111 Teapot 107 Mug 103 Pen 98 Notebook 96 Stapler 92 5 ['Notebook', 'Pen'] -> ['Gift card', 'Lamp', 'Plant'] 13 ['Teapot'] -> ['Gift card', 'Lamp', 'Plant'] 19 ['Plant'] -> ['Gift card', 'Lamp', 'Teapot']
Your task: the paid lines, bought and the loop over customers 5, 13 and 19 are already written. Count the different customers per product in popularity, sort it from the most bought down and print it with .to_string(). Then finish recommend_popular so that it adds every product the customer doesn't own to picks, most popular first.
Assignment
Follow the Coding Tutorial to count each product's customers and build the most-popular recommender.
Hint
Group the paid lines by "product" and count the different "customer_id" values. In the loop, a product goes into picks only if it is not in owned.
Free plan: 30 tutor messages. PRO is unlimited.
