Skip to content

API of recommend products - Content based and Collaborative filtering

Notifications You must be signed in to change notification settings

arnoweb/recsys-spotlight-pytorch-fastapi

Repository files navigation

Products Recommendation System - create your private A.I model and use it on your website via the build-in API

Python Version PyTorch Version Pinecone Version FastAPI Version Solara Version Spotlight Version

What is this project is for?

Rec Sys User Based

Amazon has sales that are 20% to 30% higher thanks to their product recommendation system!

Why not do it on to your e-commerce website?

You can provide recommended products on a page of your website to your users based of your internal private data (eg: your products, your users ratings, your users purchases or interactions).

It will then display relevant list of products on your website while your user is browsing your Product Page and for none connected users (content-based filtering) and connected users (collaborative filtering).

Whatever CMS (Wordpress, Drupal, Prismic, Shopify...) or custom backend (Laravel, Symfony..) you currently use, if you have data, this project can be adapted and plugged to any source of data (CSV, SQL, MongoDB, Google Big Query...) and "your own machine learning model"

You have now the API (fastApi) to list recommended products to your website based on your own Machine Learning model.

Project Overview

This project aims to build a product recommendation system that predicts relevant products for users based on their previous interactions - COLLABORATIVE FILTERING - and without interactions - ITEM BASED FILTERING -.

The recommendations are served via a REST API, with a Web UI interface to test and visualize results. The project leverages various machine learning libraries and frameworks, including PyTorch and Spotlight, to train and deploy recommendation models.

Features

  • Product Recommendations: Predicts and provides personalized product recommendations for users.
  • REST API: An API built with FastAPI to serve predictions, allowing easy integration with other applications.
  • Interactive Web UI: A web interface built with Solara (React-based) for testing and exploring recommendations.

Technologies Used

  • Python: Core language for model development, API, and backend logic.
  • PyTorch: Used as the backbone framework for building and training the recommendation model.
  • Spotlight: A recommendation library based on PyTorch, used to simplify building and training collaborative filtering models.
  • Pinecone: Used to create embeddings of data, indexing vector data and request vector data
  • FastAPI: A high-performance API framework used to expose the recommendation model for external access.
  • Solara: A React-based framework for building a Web UI, allowing users to interact with the recommendation model and visualize results.
  • DVC: is an open-source tool for versioning datasets, managing machine learning models, and ensuring reproducibility with seamless Git integration.

How to use the Recommendation System

Manage Data

  • Exploration
  • Preparation
  • Evaluation

Rec Sys Explore Data

Recommend Products based on similarities of Products - Content based Filtering

2 methods availables for vectorization of bags of words:

  • CountVectorizer
  • TfIdfVectorizer

Use of the cosine similarities matrix

solara run application/website/01-ml-recsys-content-based.py

Rec Sys Content Based - Cold Start

Create the Machine Learning Model - PyTorch Model

Via Solara:
solara run application/website/02-ml-create-model.py

Or via API endpoint:
/generateModel?data_work_type=movies

Path of the model created model/movies_users_rating_model.pth

Display the recommendation products to the user - Collaborative Filtering

Based on the machine learning model - PyTorch Model

solara run application/website/03-ml-display-rec.py

Or via API endpoint (e.g User ID:1 and recommended results up to 3):
/getRec/collaborative/movies/1/3

Rec Sys User Based

The recommended products API

Test and doc of the API (FastAPI)
http://127.0.0.1:8765/docs

Rec Sys User Based

About

API of recommend products - Content based and Collaborative filtering

Resources

Stars

Watchers

Forks

Packages

No packages published