A Simple Content-Based Recommendation Engine in Python
blog.untrod.com
blog.untrod.com
As a reader, with all of that intro, I couldn't help but be really disappointed that the implementation discussed wasn't the one relying on buying behavior... seems like a good chunk of the article is devoted to explaining why that one is a superior recommendation system, so naturally I wanted to see how you'd go about putting THAT together...
To clarify here as well:
- CF techniques are definitely superior for answering the question "what else might this user want to buy?" in a generic way, when you have preference/purchase data for that user.
- Content-based techniques are great for making recommendations in a context where what you really want is something more akin to automatic curation, and you may not have the necessary preference information about a visitor to apply CF (e.g. an anonymous user viewing a product details page, vs. a logged in user who has previously bought products). A content-based approach can solve the cold-start problem for CF.
You're right that I could have done a much better job in the original post -- I've since added information to the effect of the above. Thanks very much for the comment!
Example (frames as "customers also bought" but in reality is a set of similar products -- we swapped in the content-basd engine for a CF approach and haven't yet updated the copy): https://www.grove.co/catalog/product/cellulose-sponge/?v=802
At Conversify[0] we literally tested these methods last week(!) We help e-commerce companies with machine-learning optimizations of which a recommendation system is one. The average shop uses the standard tools for recommendations which are terrible, with some intelligence it could be a very important way to increase sales and conversion. [/end-plug]
This is what we learned. We've tested three approaches (all on sites with enough traffic):
(1) CF based on buys in combination with/without profiling
(2) CF based on purely clicks in combination with/without profiling
(3) Text analysis (sklearn, TF-IDF)
We had the best hopes for buys then clicks and as last text-analysis. It was exactly the other way around ;-).
(1) Buys has the drawback that the relationship of profiles to products is a lot to a few most of the time (relatively).
(2) Clicks has the same drawback but we can also see clicks within one session. This makes clicks somewhat better because shoppers often compare multiple products that are alike. This is valuable info.
(3) We didn't think that TF-IDF had evolved the last couple of years this much that we now can do an analysis with a few a lines of code with these results. They were stellar. We tested the outcomes with the business owners as well as customers (we didn't say which method generated which results) and they all went massively for text-analysis.
Here's our outcome for a random product from one of our customers (with a combined buys/clicks recommendation): http://i.imgur.com/lEYYIh9.png
That being said: we are working on a combination of all three methods. We think that text-analysis is for the first filtering of related products and that the CF methods are for ordering of this set. Also using weights for the different methods are useful.
Besides that we are developing a way to distinguish in an automated way between substitute products (samsung vs iphone) and complementary products (charger with a phone). This could be accomplished by using more CF than text (and specifically bought products within sessions). Our first results are promising.
Very interesting result. What techniques were you using for CF? You're right that buys:profiles ratio is a challenge, but dealing with a very sparse matrix like that is exactly what CF is for :)
You are spot on using a content-based method to limit the universe of recommendations, and then ordering them via CF. Here's someone else talking about the same approach: https://www.quora.com/Recommendation-Systems-What-is-the-dif...
I love the idea of doing substitute identification (and complementary products). I made a pass at that some months ago by using some simple statistics to identify products that are never/rarely purchased together, in spite of their relative popularity. The idea being that no one is purchasing e.g. two tubes of different brands of toothpaste together in the same basket, even though both products are independently popular. The initial test led to mixed results, but I didn't pursue it far enough to know if the results would have ultimately been viable.
I'd love to know what you find as you dig in.
Regarding the example picture I gave: that's the difference between substitutes and complementary products. The example gives alternatives (other straws...). We're building a way to have recommendations on these two types.
Why TF-IDF works better vs buys? A set of bought products holds no to little similarities between those products, it's better to use it for complementary products.
Why TF-IDF works better vs clicks? Click paths on sites are more random than you think. Combining click data with TF-IDF makes more sense.
As said: TF-IDF as a first filter and using CF as sorting could be the most optimal for substitute products. Complementary products should rely more on CF.
A problem with clicks/buys only is that new products tend to get overlooked, you can fix that by mixing in TF-IDF.
I'd encourage you to go further that tf-idf, can improve a lot keyword extraction and based on that improve your overall recommendation.
A simple, basic approach is to create a taxonomy of "entities" that you know are relevant for you. Often time these are so specific and particular that even if they appear a single time in the text they have to be considered keywords, wether tf-idf says so or not. It's clear that a text that simply reference that entity would have that as a keyword, which may be wrong, but most of the time you'll be correct.
As an example, I don't know, "coconut oil soap". Will tf-ids ever surface it? Hard to say. Is it relevant to your business and thus recommendation? I think more.
Happy to chat about this anytime, shut me an email.