EyeRecommender
A simple similarity based recommendation engine and NPM module built on top of Node.js and Redis.
The engine uses the Jaccard coefficient to determine the similarity between users and k-nearest neighbors to create recommendations.
Requirements
Installation
npm install @eyevinn/eye-recommender
Quickstart
eyeRecommender keeps track of the ratings and recommendations from your users. It does not need to store any meta data of the user or product aside from an id. To get started:
Install eyeRecommender:
npm install @eyevinn/eye-recommender
Setup Redis:
The configuration is defaulted to run against a local Redis instance.
If you want to use a remote instance, you can set the following settings in your environment
- EyeRecommender_REDIS_URL
- EyeRecommender_REDIS_PORT
- EyeRecommender_REDIS_AUTH
Example:
const eyeRecommender = require("@eyevinn/eye-recommender");
(async () => {
await eyeRecommender.input.like("Jane", "The Holiday");
await eyeRecommender.input.like("Jane", "Love Actually");
await eyeRecommender.input.like("Jane", "The Grinch");
await eyeRecommender.input.like("Carly", "The Holiday");
await eyeRecommender.input.dislike("Carly", "The Grinch");
const recommendations = await eyeRecommender.statistics.recommendationsForUser("Carly");
console.log("Recommendations for Carly", recommendations);
})()
Outputs
Recommendations for Carly [ 'Love Actually' ]
config
eyeRecommender.config.nearestNeighbors = 5;
eyeRecommender.config.className = 'movie';
eyeRecommender.config.numOfRecsStore = 30;
Full Usage
Inputs
await eyeRecommender.input.like("userId", "itemId");
await eyeRecommender.input.dislike("userId", "itemId");
await eyeRecommender.input.unlike("userId", "itemId");
await eyeRecommender.input.undislike("userId", "itemId");
Recommendations & Statistics
Recommendations
await eyeRecommender.statistics.recommendationsForUser("userId", "numberOfRecs (default 10)");
await eyeRecommender.statistics.mostSimilarUsers("userId");
await eyeRecommender.statistics.leastSimilarUsers("userId");
Statistics
await eyeRecommender.statistics.bestRated();
await eyeRecommender.statistics.worstRated();
await eyeRecommender.statistics.bestRatedWithScores("numberOfRatings (default 10)");
await eyeRecommender.statistics.mostLiked();
await eyeRecommender.statistics.mostDisliked();
await eyeRecommender.statistics.likedBy("itemId");
await eyeRecommender.statistics.likedCount("itemId");
await eyeRecommender.statistics.dislikedBy("itemId");
await eyeRecommender.statistics.dislikedCount("itemId");
await eyeRecommender.statistics.allLikedForUser("userId");
await eyeRecommender.statistics.allDislikedForUser("userId");
await eyeRecommender.statistics.allWatchedForUser("userId");
Recommendation Engine Components
Jaccard Coefficient for Similarity
There are many ways to gauge the likeness of two users. The original implementation of recommendation eyeRecommender used the Pearson Coefficient which was good for measuring discrete values in a small range (i.e. 1-5 stars). However, to optimize for quicker calcuations and a simplier interface, recommendation eyeRecommender instead uses the Jaccard Coefficient which is useful for measuring binary rating data (i.e. like/dislike). Many top companies have gone this route such as Youtube because users were primarily rating things 4-5 or 1. The choice to use the Jaccard's instead of Pearson's was largely inspired by David Celis who designed Recommendable, the top recommendation engine on Rails. The Jaccard Coefficient also pairs very well with Redis which is able to union/diff sets of like/dislikes at O(N).
K-Nearest Neighbors Algorithm for Recommendations
To deal with large user bases, it's essential to make optimizations that don't involve comparing every user against every other user. One way to deal with this is using the K-Nearest Neighbors algorithm which allows you to only compare a user against their 'nearest' neighbors. After a user's similarity is calculated with the Jaccard Coefficient, a sorted set is created which represents how similar that user is to every other. The top users from that list are considered their nearest neighbors. recommendation eyeRecommender uses a default value of 5, but this can easily be changed based on your needs.
Wilson Score Confidence Interval for a Bernoulli Parameter
If you've ever been to Amazon or another site with tons of reviews, you've probably ran into a sorted page of top ratings only to find some of the top items have only one review. The Wilson Score Interval at 95% calculates the chance that the 'real' fraction of positive ratings is at least x. This allows for you to leave off the items/products that have not been rated enough or have an abnormally high ratio. It's a great proxy for a 'best rated' list.