Public Repository

Last pushed: 2 years ago
Short Description
predictionio 0.9.2 with on Ubuntu 14.04
Full Description

predictionio-0.9.2

$ docker run -v `pwd`:/docker -p 9000:9000 -p 8000:8000 --rm -i -t predictionio /bin/bash

Once inside the container, run pio-start-all to start everything

check status $ pio status

run dashboard $ pio dashboard

The Dashboard is available on port 9000

Point browser to: http://${DOCKER_HOST}:9000

##Quick Start

  1. Go to quickstartapp directory docker/quickstartapp
  2. create a new engine from an engine template

     pio template get PredictionIO/template-scala-parallel-recommendation MyRecommendation
     cd MyRecommendation
    
  3. generate an app id and access key
    pio app new myapp

     [INFO] [HBLEvents] The table predictionio_eventdata: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: myapp
     [INFO] [App$]         ID: 1
     [INFO] [App$] Access Key: OFRuAqK32bRRBxlPNu5ccAcWRIuiuj51syiWAXUJyZLyNrRJWzI1oIKh5lUEGb9z
    

    list app

     $ pio app list
    

##Collecting data
https://docs.prediction.io/datacollection/eventapi/

example of Python SDK

import predictionio

client = predictionio.EventClient(
access_key=<ACCESS KEY>,
url=<URL OF EVENTSERVER>,
threads=5,
qsize=500
)

# A user rates an item
client.create_event(
event="rate",
entity_type="user",
entity_id=<USER ID>,
target_entity_type="item",
target_entity_id=<ITEM ID>,
properties= { "rating" : float(<RATING>) }
)

# A user buys an item
client.create_event(
event="buy",
entity_type="user",
entity_id=<USER ID>,
target_entity_type="item",
target_entity_id=<ITEM ID>
)

example of REST API

# A user rates an item
curl -i -X POST <URL OF EVENTSERVER>/events.json?accessKey=<ACCESS KEY> \
-H "Content-Type: application/json" \
-d '{
"event" : "rate",
"entityType" : "user"
"entityId" : <USER ID>,
"targetEntityType" : "item",
"targetEntityId" : <ITEM ID>,
"properties" : {
"rating" : <RATING>
}
"eventTime" : <TIME OF THIS EVENT>
}'

    # A user buys an item
    curl -i -X POST <URL OF EVENTSERVER>/events.json?accessKey=<ACCESS KEY> \
    -H "Content-Type: application/json" \
    -d '{
    "event" : "buy",
    "entityType" : "user"
"entityId" : <USER ID>,
"targetEntityType" : "item",
"targetEntityId" : <ITEM ID>,
"eventTime" : <TIME OF THIS EVENT>
}'

##Import sample data

KEY=OFRuAqK32bRRBxlPNu5ccAcWRIuiuj51syiWAXUJyZLyNrRJWzI1oIKh5lUEGb9z

curl https://raw.githubusercontent.com/apache/spark/master/data/mllib/sample_movielens_data.txt --create-dirs -o data/sample_movielens_data.txt

python data/import_eventserver.py --access_key $KEY

##Deploy the Engine as a Service

cd MyRecommendation
# edit engine.json and make sure the appName parameter match your App Name you created earlier

##Building

cd MyRecommendation
pio build
...
[INFO] [Console$] Your engine is ready for training.

##Training the Predictive Model

pio train

##Deploy the Engine

pio deploy --ip 0.0.0.0

this command will binds to http://localhost:8000

point your browser to: http://192.168.59.103:8000

##Use the Engine

Now, You can try to retrieve predicted results. To recommend 4 movies to user whose id is 1, you send this JSON { "user": "1", "num": 4 } to the deployed engine and it will return a JSON of the recommended movies. Simply send a query by making a HTTP request or through the EngineClient of an SDK:

import predictionio
engine_client = predictionio.EngineClient(url="http://localhost:8000")
print engine_client.send_query({"user": "1", "num": 4})
$ curl -H "Content-Type: application/json" -d '{ "user": "1", "num": 4 }' http://192.168.59.103:8000/queries.json

# response
{"itemScores":[{"item":"90","score":7.633921967322186},{"item":"38","score":7.572087692133769},{"item":"1","score":7.442507843104263},{"item":"32","score":7.14897953079582}]}n

note: To update the model periodically with new data, simply set up a cron job to call pio train and pio deploy. The engine will continue to serve prediction results during the re-train process. After the training is completed, pio deploy will automatically shutdown the existing engine server and bring up a new process on the same port.

more info: https://docs.prediction.io/templates/recommendation/quickstart/

##Config

PredictionIO-0.9.2/conf/pio-env.sh

see: https://docs.prediction.io/install/install-linux/

Docker Pull Command
Owner
naosato

Comments (0)