npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@eyevinn/eye-recommender

v0.0.1

Published

A Recommendation Engine built on Node.js utilizing Redis

Downloads

7

Readme

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

  • Node.js 10.x
  • Redis

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

// these are the default values but you can change them
eyeRecommender.config.nearestNeighbors = 5;  // number of neighbors you want to compare a user against
eyeRecommender.config.className = 'movie';  // prefix for your items (used for redis)
eyeRecommender.config.numOfRecsStore = 30;  // number of recommendations to store per user

Full Usage

Inputs

// to set ratings
await eyeRecommender.input.like("userId", "itemId");
await eyeRecommender.input.dislike("userId", "itemId");
// to remove already set ratings
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

/**
 * Item related
 */
await eyeRecommender.statistics.bestRated();
await eyeRecommender.statistics.worstRated();
await eyeRecommender.statistics.bestRatedWithScores("numberOfRatings (default 10)");
await eyeRecommender.statistics.mostLiked();
await eyeRecommender.statistics.mostDisliked();
// Get a list of users who liked a given asset
await eyeRecommender.statistics.likedBy("itemId");
// Get the amount of users who liked a given asset
await eyeRecommender.statistics.likedCount("itemId");
// Get a list of users who disliked a given asset
await eyeRecommender.statistics.dislikedBy("itemId");
// Get the amount of users who disliked a given asset
await eyeRecommender.statistics.dislikedCount("itemId");

/**
 * User related
 */

// Get a list of items that the given user has liked
await eyeRecommender.statistics.allLikedForUser("userId");
// Get a list of items that the given user has disliked
await eyeRecommender.statistics.allDislikedForUser("userId");
// Get a list of items that the given user has rated
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.

Heavily inspired by recommendationRaccoon.