Skip to main content

Recommendations for .NET using collaborative filtering

Total Downloads
787
787
Published
May 11, 2025
1y ago

Get Started

dotnet add package DiscoRec --version 0.1.2
ProductVersions
.NET
net6.0

README

Disco.NET

Recommendations for .NET using collaborative filtering

  • Supports user-based and item-based recommendations
  • Works with explicit and implicit feedback
  • Uses high-performance matrix factorization

Build Status

Installation

Run

dotnet add package DiscoRec

Getting Started

Import the library

using DiscoRec;

Prep your data in the format userId, itemId, value

var data = new Dataset<string, string>();
data.Add("user_a", "item_a", 5.0f);
data.Add("user_a", "item_b", 3.5f);
data.Add("user_b", "item_a", 4.0f);

IDs can be integers or strings

data.Add(1, "item_a", 5.0f);

If users rate items directly, this is known as explicit feedback. Fit the recommender with:

var recommender = Recommender<string, string>.FitExplicit(data);

If users don’t rate items directly (for instance, they’re purchasing items or reading posts), this is known as implicit feedback. Leave out the rating.

var data = new Dataset<string, string>();
data.Add("user_a", "item_a");
data.Add("user_a", "item_b");
data.Add("user_b", "item_a");

var recommender = Recommender<string, string>.FitImplicit(data);

Each userId/itemId combination should only appear once

Get user-based recommendations - “users like you also liked”

recommender.UserRecs(userId, 5);

Get item-based recommendations - “users who liked this item also liked”

recommender.ItemRecs(itemId, 5);

Get the predicted rating for a specific user and item

recommender.Predict(userId, itemId);

Get similar users

recommender.SimilarUsers(userId, 5);

Examples

MovieLens

Load the data

var data = await Data.LoadMovieLens();

Create a recommender

var recommender = Recommender<int, string>.FitExplicit(data, new RecommenderOptions { Factors = 20 });

Get similar movies

var recs = recommender.ItemRecs("Star Wars (1977)", 5);
foreach (var rec in recs)
    Console.WriteLine("{0}: {1}", rec.Id, rec.Score);

Storing Recommendations

Save recommendations to your database.

Alternatively, you can store only the factors and use a library like pgvector-dotnet. See an example.

Algorithms

Disco uses high-performance matrix factorization.

Specify the number of factors and iterations

var recommender = Recommender<string, string>.FitExplicit(data, new RecommenderOptions { Factors = 8, Iterations = 20 });

Validation

Pass a validation set

var recommender = Recommender<string, string>.FitExplicit(trainSet, validSet);

Cold Start

Collaborative filtering suffers from the cold start problem. It’s unable to make good recommendations without data on a user or item, which is problematic for new users and items.

recommender.UserRecs(newUserId, 5);

There are a number of ways to deal with this, but here are some common ones:

  • For user-based recommendations, show new users the most popular items
  • For item-based recommendations, make content-based recommendations

Reference

Get ids

recommender.UserIds();
recommender.ItemIds();

Get the global mean

recommender.GlobalMean();

Get factors

recommender.UserFactors(userId);
recommender.ItemFactors(itemId);

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/disco-dotnet.git
cd disco-dotnet
dotnet test

Downloads by Version

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.