AI Beyond Language Models ยท Everyday AI
Streaming and shopping sites suggest things by finding people whose tastes match yours. Compare ratings, find the closest viewer, and recommend what they loved.
# Recommend a film: find the viewer whose ratings look most like yours, and suggest what they loved.
films = ["Space Race", "Love Boat", "Robot Wars", "Old Town"]
ratings = {"you": [5, 1, 4, 0], "ana": [4, 2, 5, 5], "raj": [1, 5, 1, 4]} # 0 = not seen
others = ["ana", "raj"]
distances = []
for name in others:
distances.append(sum([abs(a - b) for a, b in zip(ratings["you"][:3], ratings[name][:3])]))
closest = others[distances.index(min(distances))]
unseen = films[ratings["you"].index(0)]
print("try", unseen, "- rated", ratings[closest][films.index(unseen)], "by", closest)name is created with the value 'ana'.name changes from 'ana' to 'raj'.for name in others.