People who bought also bought..

Recommendation systems are everywhere. Right from amazon.com, netflix, youtube, super market’s advertising..and where not!
When it all started a few years back, I used to think, wow! How does amazon knows which dress I might like next? That was really interesting. Now we all know that it’s the magic of data science. Machine learning algorithms are continuously capturing the data, learning from it and providing the recommendations. Today we are going through it in a bit more detail. 

So, how data can predict what the user is gonna like or gonna buy? Based on prior knowledge. And here comes our first Association Rule Learning Algorithms, Apriori. The name tells us, that it’s going to predict something based on prior knowledge. Apriori works on 3 factors. Support, Confidence and Lift.

Lets say, out of 100 people, 10 people like the movie ‘fantastic beasts and where to find them’. So, we can predict that the probability is 10%, for any other set of netflix watchers. This is gonna be our Support. Another example of calculating support is, let's say we want to create a recommender system for a grocery shop. Here, we should not concentrate on items which are purchased infrequently. We would like to look at most popular products and build a model on it. If item x is purached at least 20 times in a week, then ’20/ total number of transaction in a week’ could be the value for Support.
Now back to our movies example, if we recommend this movie to 100 people 10 people will actually watch it. Can we improve the result by making targeted recommendations?
Let’s see. Out of these same 100 people, 40 people are fan of Harry Potter movies. And, out of these 40 people, 7 people have liked Fantastic Beats. That is 7/40 17.5% have liked Fantastic Beats. This is the value of our Confidence parameter. So, if we recommend randomly, only 10% is the probability that people are gonna like this movie. But when we recommend to people who have already watched Harry Potter, 17.5% people might like this movie. 

Let’s calculate Lift now. Lift is nothing but the improvement we have achieved by applying the algorithm. 17.5% /  10% = 1.75 is the lift. The maximum is the lift, better the rule.

Another similar algorithm for association rule learning is Eclat. This is simpler and faster compared to Apriori. 
Here, we observe how many people have liked both the movies. Eclat finds out the lists of things which often come together. e.g. customer order’s  which contains milk and bread together out of total customer orders. Here support is calculated as number of times the item has appeared with other item/ total number of orders. 

R and Python has libraries for these algorithms. While implementing this algorithm, We need to convert the dataset into a sparse matrix. And create the models using respective functions. Choose parameters as explained above. The output of these functions will be a set of Rules. Sort the rules by Lift to get the most appropriate rules.  Do explore these functions in R and Python, they are very easy to implement, but of course we need to try them with different set of values for parameters support and confidence, to get the optimal results. I will post a link here of my kaggle kernel if I can find a sample data set suitable for building a recommendation system.


Till then, bye!

Comments

Popular posts from this blog

Understanding Wide-Column Stores

Two pizza team!

Relational and Non-relational databases