Start event server:
$ pio eventserver &
Create new application:
$ pio app new MyApp1
$ export ACCESS_KEY=<ACCESS_KEY>
Test event server by importing event data:
$ curl -i -X POST http://localhost:7070/events.json?accessKey=$ACCESS_KEY \
-H "Content-Type: application/json" \
-d '{
"event" : "rate",
"entityType" : "user",
"entityId" : "u0",
"targetEntityType" : "item",
"targetEntityId" : "i0",
"properties" : {
"rating" : 5
}
"eventTime" : "2014-11-02T09:39:45.618-08:00"
}'
$ curl -i -X POST http://localhost:7070/events.json?accessKey=$ACCESS_KEY \
-H "Content-Type: application/json" \
-d '{
"event" : "buy",
"entityType" : "user",
"entityId" : "u1",
"targetEntityType" : "item",
"targetEntityId" : "i2",
"eventTime" : "2014-11-10T12:34:56.123-08:00"
}'
$ curl "http://localhost:7070/events.json?accessKey=$ACCESS_KEY"
Clone engine template:
$ git clone https://github.com/apache/predictionio-template-recommender.git
$ cd predictionio-template-recommender
Edit engine.json
:
...
"datasource": {
"params" : {
"appName": "MyApp1" // <- Edit appName
}
},
...
Edit src/main/scala/ALSAlgorithm.scala
:
sc.setCheckpointDir("checkpoint") // <- activate this line to avoid StackOverflowError
Import event data in bulk:
$ 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 $ACCESS_KEY
Build engine:
$ pio build
Train model:
$ pio train
Deploy model as Web API:
$ pio deploy
Access to http://localhost:8000 to see the status of Web API.
Test prediction Web API:
$ curl http://localhost:8000/queries.json -H "Content-Type: application/json" -d '{ "user": "1", "num": 4 }'