Unified recommender

Now let's create a unified recommender using the template provided by PredictionIO project.

$ mkdir ~/tmp
$ cd ~/tmp
$ pio template get PredictionIO/template-scala-parallel-universal-recommendation urec-app
Please enter the template's Scala package name (e.g. com.mycompany): com.example.urec
Author's name:    My Name
Author's e-mail:   [email protected]
Author's organization: com.example.urec
... OUTPUT SKIPPED ... 
Engine template PredictionIO/template-scala-parallel-universal-recommendation is now ready at urec-app

Create a Git repository for the app we just created. This will help us track our local changes:

$ cd urec-app
$ git init .
$ git add .

Update the appName in engine.json to urec-app as shown in the following Git diff:

$ git diff
diff --git a/engine.json b/engine.json
index 495de5c..f371d40 100644
--- a/engine.json
+++ b/engine.json
@@ -5,7 +5,7 @@
 "datasource": {
  "params" : {
   "name": "sample-handmade-data.txt",
-   "appName": "handmade",
+   "appName": "urec-app",
   "eventNames": ["purchase", "view"]
  }
 },
@@ -22,7 +22,7 @@
   "comment": "setup for example 'handmade' data, make sure to change for your needs",
   "name": "ur",
   "params": {
-    "appName": "handmade",
+    "appName": "urec-app",
    "indexName": "urindex",
    "typeName": "items",
    "eventNames": ["purchase", "view"]

Now start all Prediction IO services:

$ pio-start-all
Starting Elasticsearch...
Starting HBase...
starting master, logging to /home/tuxdna/PredictionIO/vendors/hbase-1.0.0/bin/../logs/hbase-tuxdna-master-matrix02.out
Waiting 10 seconds for HBase to fully initialize...
Starting PredictionIO Event Server...

From the application template, we ask PredictionIO to initialize the app:

$ pio app new urec-app
[INFO] [HBLEvents] The table pio_event:events_1 doesn't exist yet. Creating now...
[INFO] [App$] Initialized Event Store for this app ID: 1.
[INFO] [App$] Created new app:
[INFO] [App$]   Name: urec-app
[INFO] [App$]    ID: 1
[INFO] [App$] Access Key: fwqjaPTyhzPScEBP8kl05EEQCExrRZ2zds0EeDpA23MwnAyPvTlw9ANQSKZ2k1Wl

You must note the access key generated in the preceding output, as it is used for all subsequent operations. In the template the examples data is populated using PredictionIO Python API, we also install them:

$ sudo pip install PredictionIO

Now import sample data using the access key we received for our app:

~/tmp/urec-app$ python examples/import_handmade_eventserver.py --access_key fwqjaPTyhzPScEBP8kl05EEQCExrRZ2zds0EeDpA23MwnAyPvTlw9ANQSKZ2k1Wl
Namespace(access_key='fwqjaPTyhzPScEBP8kl05EEQCExrRZ2zds0EeDpA23MwnAyPvTlw9ANQSKZ2k1Wl', file='./data/sample-handmade-data.txt', url='http://localhost:7070')
Importing data...
Event: purchase entity_id: u1 target_entity_id: iphone
... OUTPUT SKIPPED ... 
Event: view entity_id: u1 target_entity_id: phones
... OUTPUT SKIPPED ... 
Event: $set entity_id: iphone properties/catagory: phones
... OUTPUT SKIPPED ... 
22 events are imported.

Now build the engine, train and then finally deploy it shown as follows:

$ pio build
[INFO] [Console$] Using existing engine manifest JSON at /home/tuxdna/tmp/urec-app/manifest.json
... OUTPUT SKIPPED ... 
[INFO] [RegisterEngine$] Registering engine BqyQGKT8gmWjn9cNY0r9MJMVsF5cNemM f1a7b261ef8ab87d2bd107c4214fc648f2db4617
[INFO] [Console$] Your engine is ready for training.

The training commands are as follows:

$ pio train -- --driver-memory 8G --executor-memory 8G
[INFO] [Console$] Using existing engine manifest JSON at /home/tuxdna/tmp/urec-app/manifest.json
... OUTPUT SKIPPED ... 
[INFO] [CoreWorkflow$] Updating engine instance
[INFO] [CoreWorkflow$] Training completed successfully.

Finally, deploy it to the PredictionIO cluster:

$ pio deploy
... OUTPUT SKIPPED ... 
[INFO] [MasterActor] Engine is deployed and running. Engine API is live at http://0.0.0.0:8000.

Once it is deployed, you can see it running on the web browser:

Unified recommender

In the following figure, we can see that our app using URAlgorithm is deployed, along with its parameters:

Unified recommender

Please note here that we are using PredictionIO version 0.9.4, and in an upcoming release some changes may break the commands we have used. Now let's query the engine for recommendations:

$ sh ./examples/query-handmade.sh 

Recommendations for user: u1
{"itemScores":[{"item":"galaxy","score":0.7635629773139954},{"item":"nexus","score":0.06365098059177399},{"item":"surface","score":0.0482502318918705}]}
 ... OUTPUT SKIPPED ...

The preceding command makes a query to PredictionIO app where our recommendation algorithm is running. The query returned some recommendations for user u1. With this approach all the development and deployment of a recommendation becomes much simpler, and easy to maintain and evaluate. Using a server like PredictionIO we can now focus on building our core piece, that is, the recommendation engine.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.173.199