The recommender and visualization can be found here: http://52.14.98.50:5000/recommender
This project is best summarized by its parts:
-
deployment of a factorization machine recommender in a production environment. This includes:
- Building a deployable factorization machine recommender
- Building a RESTFUL API for hosting a factorization machine recommender
-
Building front-end UI for visualizing recommendations and similar items. The visualizations built include:
To demonstrate the deployment of a factorization machine model, I utilize a well studied dataset of 10M interactions between users and movies). I began by first exploring the dataset, followed by implementing methods to clean and prepare the data, and finally modeling. To build the recommendation models, I utilize factorization machine algorithms via lightfm, a wonderful library written by Maciej Kula. Further reading can be found here. Upon building a suitable model, I consolidated the preprocessing and modeling code into a single python class labelled FM. This class was designed for a simplified deployment process.
Jupyter was utilized in the development stage. Some notebooks of interest are:
- Exploratory analysis for defining cleaning and preprocessing requirements.
- Performance analysis of factorization machine models compared to a popularity baseline
- Similar Item Analysis calculated via cosine similarity of factorization machine embedding vectors
Next, a deployable train.py
script was built. This script executes the following components:
- ingests data
- preprocesses data
- trains factorization machine
- serializes factorization machine to disk
Once a model is serialized and stored to disk, it's time to build a RESTFUL API for hosting it.
For real time recommendations, a trained model must be loaded into a server's memory and called behind a RESTFUL endpoint. To setup the server and endpoints, I utilized Flask. The app server code can be found in app_svc.py
. We create the following endpoints on our server for real time requests:
rec_predict
- for both personalized and popularity recommendationsget_historical_likes
- to see what a user has liked in the pastget_similar_movies
- to find similar movies to one you input
Also built into the app server are routes for visualizing the results of the deployed recommender. Specifically, two routes are defined in the server:
- http://52.14.98.50:5000/recommender where the route is defined by this server code
- http://52.14.98.50:5000/similar_movies where the route is defined by this server code
The GET requests at these routes return a static html. Javascript is utilized to interact with html and make async POST requests to the real-time recommendation endpoints described above. It also enables a nice user experience for engaging and interacting with the deployed recommender model.