Giter VIP home page Giter VIP logo

predictionio-buildpack's Introduction

PredictionIO classification app

Predictive classification powered by PredictionIO, machine learning on Heroku.

This is a demo application of PredictionIO version 0.9.5, already customized for the smoothest experience possible. Custom PredictionIO engines may be deployed as well, see CUSTOM documentation.

How To ๐Ÿ“š

โœ๏ธ Throughout this document, code terms that start with $ represent a value (shell variable) that should be replaced with a customized value, e.g $eventserver_name, $engine_name, $postgres_addon_idโ€ฆ

Deploy to Heroku

Please follow steps in order.

  1. Requirements
  2. Eventserver
  3. Create the eventserver
  4. Deploy the eventserver
  5. Classification engine
  6. Create the engine
  7. Connect the engine with the eventserver
  8. Import data
  9. Deploy the engine

Usage

Once deployed, how to work with the engine.

Deploy to Heroku ๐Ÿš€

1. Requirements

2. Eventserver

Create the eventserver

git clone \
  https://github.com/heroku/predictionio-buildpack.git \
  pio-eventserver-classification

cd pio-eventserver-classification

heroku create $eventserver_name
heroku addons:create heroku-postgresql:hobby-dev
heroku buildpacks:add -i 1 https://github.com/heroku/predictionio-buildpack.git
heroku buildpacks:add -i 2 heroku/scala

Deploy the eventserver

We delay deployment until the database is ready.

heroku pg:wait && git push heroku master

3. Classification Engine

Create the engine

git clone \
  https://github.com/heroku/predictionio-engine-classification.git \
  predictionio-engine-classification

cd predictionio-engine-classification

heroku create $engine_name
heroku buildpacks:add -i 1 https://github.com/heroku/heroku-buildpack-jvm-common.git
heroku buildpacks:add -i 2 https://github.com/heroku/predictionio-buildpack.git

Connect the engine with the eventserver

First, collect a few configuration values.

Get the eventserver's database add-on ID

heroku addons:info heroku-postgresql --app $eventserver_name
#
# Use the returned Postgres add-on ID
# to attach it to the engine.
# Example: `postgresql-aerodynamic-00000`
#
heroku addons:attach $postgres_addon_id --app $engine_name

Get an access key for this engine's data

heroku run 'pio app new classi' --app $eventserver_name
#
# Use the returned access key for `$pio_app_access_key`
#
heroku config:set \
  PIO_EVENTSERVER_HOSTNAME=$eventserver_name.herokuapp.com \
  PIO_EVENTSERVER_PORT=80 \
  PIO_EVENTSERVER_ACCESS_KEY=$pio_app_access_key \
  PIO_EVENTSERVER_APP_NAME=classi

Import data

๐Ÿšจ Mandatory: data is required for training to succeed and then to serve predictive queries.

  • pip install predictionio may be required for the import script to run; see how-to install pip
python ./data/import_eventserver.py \
  --url https://$eventserver_name.herokuapp.com \
  --access_key $pio_app_access_key

Deploy the engine

git push heroku master
#
# Follow the logs to see training 
# and then start-up of the engine.
#
heroku logs -t --app $engine_name

Usage โŒจ๏ธ

Scale up

Once deployed, scale up the processes to avoid memory issues:

heroku ps:scale \
  web=1:Standard-2X \
  release=0:Performance-L \
  train=0:Performance-L \
  --app $engine_name

Query for predictions

When deployed, the model was auto-trained to predict the best fitting service plan for a mobile phone user based on their voice, data and text usage.

Submit queries containing these three user properties to get a prediction for the best fitting service plan:

curl -X POST https://$engine_name.herokuapp.com/queries.json \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '{ "voice_usage":10, "data_usage":26, "text_usage":30 }'

curl -X POST https://$engine_name.herokuapp.com/queries.json \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '{ "voice_usage":58, "data_usage":26, "text_usage":300 }'

This model is simplified for demonstration. For a real-world model, more aspects of a user account should be taken into consideration:

  • account type: individual, business, or family
  • how frequently do they roam
  • do they roam internationally
  • kind of device: smart phone or feature phone
  • age of device

The training dataset is crucial to the relevancy of predictions. Expirementation with your unique data is a must.

See usage details for this classification engine in the PredictionIO docs.

Diagnostics

If you hit any snags with the engine serving queries, check the logs:

heroku logs -t --app $engine_name

If errors are occuring, sometimes a restart will help:

heroku restart --app $engine_name

Going Deeper ๐Ÿ”ฌ

This is a demo application of PredictionIO, already customized for the smoothest experience possible.

Custom PredictionIO engines may be deployed with this buildpack too. See CUSTOM documentation.

More details including training, evaluation, & configuration are explained there to.

predictionio-buildpack's People

Contributors

jamesward avatar mars avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.