Recommender System

In this Recommendation System example, we demonstrate the workings of a model that recommends movies to users, based on what it thinks would rate high on the user’s preference list

Powerful recommendations can be made if recommendations are based not only on the users’ past actions, but also those of all other users. The best examples of this are found on Amazon.com …”Users like you liked the following products”. This type of recommendation is called Collaborative Filtering. The model we built is one type of collaborative filtering, called Item-Item Similarity, we built a simple model from scratch using pandas.

Please look at the notebook in the rorodata github repository here for more details about the modelling and data that went into this effort.

Productionizing Machine Learning Models

Below, we discuss how a data scientist can deploy and manage data science models in production using rorodata platform, with just a few simple lines of command from a CLI. In this writeup, we shall illustrate this using Python, a similar write-up for R is on the way.

There is a lot that goes on behind the scenes in the rorodata platform. It may be hard to appreciate the demo without some understanding of this. For a quick, high level view of the rorodata platform and it's workings, go here.

Prerequisites

  • Download roro client for python3 using pip Note that currently, we only support python 3.5 and above pip install roro
  • You must have a rorodata platform account, as the models will be deployed on rorodata platform for this example. You may request access here.

Summary

$ git clone https://github.com/rorodata/recommender-system-demo.git
$ cd recommender-system-demo

# NOTE: edit roro.yml to change project name to name of new project, I am using the project name image-recognition for this example

$ roro create <your-project-name>
Created project: <your-project-name>

$ roro deploy
Deploying project <your-project-name>. This may take a few moments ...
Restarted one service
default: https://<your-project-name>.rorocloud.io/

# Inspect processes, just to check if the service is running

$ roro ps
JOBID     STATUS    WHEN            TIME     INSTANCE TYPE    CMD
--------  --------  --------------  -------  ---------------  -------------------------------------
b0905fk7t  running   1 minute ago    0:01:43  C1               firefly -b 0.0.0.0:8080 train.predict

Step 1

Clone the code repository rorodata/credit-scoring-demo (manually or using git) and download the files to a local directory. You will shortly deploy this repository on rorocloud as your own project.

$ git clone https://github.com/rorodata/recommender-system-demo.git
$ cd recommender-system-demo

Now, login to the rorodata platform using roro login from command prompt. You are now using roro client connected to rorodata platform. Send us an email if you run into any issues and we shall help you out quickly.

Step 2

Pick a unique project name for the project you are about to create on the data platform. Remember to keep a short readable name without spaces or special characters (hyphen is ok).

# NOTE: edit roro.yml to change project name to name of new project

$ roro create <your-project-name>
Created project: <your-project-name>

Step 3

Edit the roro.yml file, and change the part after project: to match your project name exactly, and save it. The roro.yml is a simple text file that tells the rorodata platform what to do during deployment. You can understand more about the structure and specifications that can go into the YML file.

Create your (new) project using the command roro create your-project-name. Remember to us the same name you picked in Step 2 & 3. Remember, this project is the entire machine learning application including its code, all associated tasks and services, persistent data volumes, and ML models. Once done, you can use the command roro projects to view a list of all your projects. Make sure that you can see the project you just created.

Your edited roro.yml should look something like this:

project: <your-project-name> 
runtime: rorodata/sandbox

services:
    - name: default
      function: train.predict

This will take a couple of minutes as the machine loads all dependencies and readies the selected machine.

Step 4

You are now ready to deploy your project code to production. From the same command prompt location as in the previous step, type roro deployand press enter. When a project is deployed, rorodata takes its cue from the roro.yml file and execute deployment steps one by one. You can see a list / trace of all these steps once roro deploy finishes.

$ roro deploy
Deploying project <your-project-name>. This may take a few moments ...
Restarted one service

default: https://<your-project-name>.rorocloud.io/

Step 5

Your services should now be ready and serving, with URL endpoints for each service as instructed by you in the roro.yml file. You can check if the service is running using the command roro ps –a. In rare cases, the service may fail due to a conflict e.g. if the trained model was not available at the time of launching service. Simple rerun roro deploy from the command prompt and the service will come up.

Step 6

The rorodata platform services are REST-APIs, and can be accessed using any client service. The easiest way to test this is through our firefly library. You can install this using pip install firefly-python and query the service using the same example as in the notebook.

Let’s now use the API we created, to predict if we should give loan to a new applicant, using his data attributes as inputs to our model.

# We will use firefly to call our API, you can use any other library e.g. Requests
>> import firefly

# Change the below statement to match your prediction service api name
>> reco_api=firefly.Client("https://<your-project-name>.rorocloud.io/")

>> print(reco_api.predict(user_id=25))
[{'item_id': 172, 'rating': 4.3662479999862915},
 {'item_id': 117, 'rating': 4.280060547219385},
 {'item_id': 328, 'rating': 4.268231762980369},
 {'item_id': 313, 'rating': 4.257574870784335},
 {'item_id': 15, 'rating': 4.251003373398124},
 {'item_id': 748, 'rating': 4.249858927495112},
 {'item_id': 294, 'rating': 4.240991333210962},
 {'item_id': 237, 'rating': 4.205707885247557},
 {'item_id': 22, 'rating': 4.205464728287706},
 {'item_id': 288, 'rating': 4.18777766572117}]

results matching ""

    No results matching ""