Understanding recommendations systems

Sumeet More
3 min readApr 26, 2020

--

Suppose you are owner of newly opened cafe called XYZ and they serve three dishes( hot pepper shawrma, pancakes, banana chips)( you must be like are you serious sumit?LOL). Owner calls top 10 flood bloggers to rate each item and understand their views. Data looks following

userid : unique blogger

foodid : unique food id

rating : Out of 5

foodname: name of the dish

3 dishes(banana chips, pancakes, hot pepper shawrma) fall in 3 categories respectively(savoury, sweet, spicy).

Each food blogger has preferences like user 1 will have preference for sweet over spicy etc. if we see pancake, it is sweet dish. With this information, owner comes up with following tabular data.

we can see user u1 likes sweet dish(3 out of 5), hates spicy ones(1 out of 5), savoury dishes are her favourites( 4 out of 5). Similarly, for pancake dish, owner knows it will be sweet so he fills (5 out of 5) and similarly rest. If we take dot product of user(U1[3,1,4]) taste preferences and dishes available in the cafe, we can see which dish a particular blogger will mostly like and get rating accordingly.

At some point, data will look like this

This 2D array tells us a lot. What is preference of a food blogger and when we know preference we can recommend.

But Sumit recommendation systems are machine learning models right? where is training model here and all? 2D array which is calculated array is actually our output and user preferences and dish categories are weight and biases of our model so we will keep iterating our calculations and stop when we reach matrix closer to 2d calculated array. Pause for a while, reread it incase you not clear because this paragraph is heart of our solution.(drop me a comment if you didn’t get this one).

Careful reader might have catched this if we know user preferences (in terms of sweet, savoury and spicy) and we know category of the dish(spicy, sweet or savoury), we can calculate ratings of any user for any dish. Other way if we know weights and biases, we should be good to predict ratings.

Now owner is little confident. First customer comes in, she says she likes pancakes and to increase sale of his cafe, he needs to suggest which dish can gone with it? he looks up in system and recommendation system is there to help him 😉.

Code :

sample output :

Careful reader will have a doubt that what if user is new and we have no clue about its preferences, answer is simple: suggest most popular dish of the cafe.😉

I hope you enjoyed reading this article and in technical term this technique is called Matrix factorization.

Inspiration for this article was this video by Luis. https://youtu.be/ZspR5PZemcs. Highly Recommended.🙌

--

--

Sumeet More
Sumeet More

Written by Sumeet More

Software Engineer 2 at Microsoft | Backend Engineer and Architect| Blockchain & ML enthusiast | C#,.NET Core, Rust, Javascript and Go

Responses (1)