Recommendation Engine ALS

Author : Rajdeep Dua
Last Updated : Dec 2 2016

Introduction

In this exercise we will create a simple recommendation engine based on Alternative Least Square Algorithm.

We will use the Pre-installed setup in our VM

MyRecommendation template has been downloaded to /home/ubuntu/work/0.10.0/incubator-predictionio/PredictionIO-0.10.0-incubating/MyRecommendation

Event Server

  1. Start the Event Server

    ./bin/pio eventserver &
    

    You can check status of the event server by going to the following url http://localhost:7070

    ../_images/pio-eventserver-status.png
  2. Create a new App by giving an access key. You can generate your own access key here https://www.uuidgenerator.net/version4

    cd MyRecommendation
    
    ../bin/pio app new MyApp1 --access-key ee7694ba-b3b9-11e6-80f5-76304dec7eb7
    
  3. Export the Access Key into an Environment Variable

    export ACCESS_KEY=ee7694ba-b3b9-11e6-80f5-76304dec7eb7
    
  4. Import Data into Event Server

    python data/import_eventserver.py --access_key $ACCESS_KEY
    
  5. View the Events in the Browser at the url http://localhost:7070/events.json?accessKey=ee7694ba-b3b9-11e6-80f5-76304dec7eb7&limit=-1

../_images/pio-eventserver-events.png

Recommendation Engine

  1. Build the Engine

    ../bin/pio build --verbose
    
    ...
    
    [INFO] [Console$] Your engine is ready for training.
    
  2. Train the Engine

    ../bin/pio train
    

    Output will be similar to listing below

    [INFO] [Engine$] org.apache.spark.mllib.recommendation.
    ALSModel does not support data sanity check. Skipping check.
    [INFO] [Engine$] EngineWorkflow.train completed
    [INFO] [Engine] engineInstanceId=7cb0a26d-f2e6-4954-9831-67944a625ac6
    [INFO] [CoreWorkflow$] Inserting persistent model
    [INFO] [CoreWorkflow$] Updating engine instance
    [INFO] [CoreWorkflow$] Training completed successfully.
    
  3. Start the Engine

    ../bin/pio deploy
    

    Output will be similar to listing below. In our case engine is listening at http://0.0.0.0:8000

    INFO] [HttpListener] Bound to /0.0.0.0:8000
    [INFO] [MasterActor] Engine is deployed and running.
    Engine API is live at http://0.0.0.0:8000.
    

Browse to the link http://0.0.0.0:8000 to see the Engine output.

../_images/pio-recommendation-engine.png

Find Recommendations

Query the Engine Rest Endpoint above

curl -H "Content-Type: application/json" \
 -d '{ "user": "1", "num": 4 }' http://0.0.0.0:8000/queries.json

Output

{"itemScores":
    [{"item":"1","score":6.25194456006901},
     {"item":"90","score":5.8767988585600754},
     {"item":"80","score":5.719902830242281},
     {"item":"8","score":5.670593027497959}
     ]
}