Giter VIP home page Giter VIP logo

predictionapi's Introduction

PredictionAPI

This is a tutorial on serving predictions from a machine learning model through a REST API.

A version of this tutorial was presented in the PyParis conference on 13/06/2017.

A complete written version is currently in the making.

Steps

  1. training and persisting the model on disk (cf. modeling.ipynb),
  2. reproducing the pre-processing pipeline in the API application (cf. application.py),
  3. encapsulating the application in a Docker container (cf. Dockerfile),
  4. deploying the application to a cloud server.

Technical Requirements

  • Python 3.5+ and virtualenv,
  • Docker,
  • The required Python librairies used can be installed from the included requirements.txt file:
virtualenv -p python3 pyenv
source pyenv/bin/activate
pip install -r requirements.txt

Running the application locally

Directly

cd PredictionAPI
export FLASK_APP=application.py
python3 -m flask run

On Docker

cd PredictionAPI
docker build -t prediction-api .
docker run -d --rm -p 5000:5000 prediction-api

Testing the application

Once it is running, the API can be queried using HTTP POST requests. This can be done from the CLI using curl or through a GUI REST client like Insomnia or Postman.

URL: http://0.0.0.0:5000/api/v1.0/aballone

Here is a sample query:

{    
  "inputs": [
    {
      "sex":"M",
      "length": 0.815000,
      "diameter": 0.055000,
      "height": 1.130000,
      "whole_weight": 2.825500,
      "shucked_weight": 1.488000,
      "viscera_weight": 0.760000,
      "shell_weight": 0.001500
    },
    {
      "sex":"F",
      "length": 0.815000,
      "diameter": 1.055000,
      "height": 1.130000,
      "whole_weight": 2.825500,
      "shucked_weight": 1.488000,
      "viscera_weight": 1.760000,
      "shell_weight": 0.001500
    }
  ]
}

The response should look like this:

{
  "outputs": [
    {
      "label": 1,
      "prob": 0.109
    },
    {
      "label": 1,
      "prob": 0.183
    }
  ]
}

predictionapi's People

Contributors

nawfaltachfine avatar

Stargazers

 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.