DiscoRec 0.1.0

dotnet add package DiscoRec --version 0.1.0                
NuGet\Install-Package DiscoRec -Version 0.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DiscoRec" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DiscoRec --version 0.1.0                
#r "nuget: DiscoRec, 0.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DiscoRec as a Cake Addin
#addin nuget:?package=DiscoRec&version=0.1.0

// Install DiscoRec as a Cake Tool
#tool nuget:?package=DiscoRec&version=0.1.0                

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 predicted ratings 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)");
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
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on DiscoRec:

Repository Stars
pgvector/pgvector-dotnet
pgvector support for .NET (C#, F#, and Visual Basic)
Version Downloads Last updated
0.1.0 90 7/21/2024