Skip to main content

This is a package which aims to combine the lighweight web-framework flask

Project description

logo

This is a repository for the open-source project Flaskriver. It combines the lightweight web-framework Flask with the online-ML library River to make deploying online-ML models to web web easier. For more info on online-ML check out the river repository or the official website.

Introduction

First you will have to install the package via pip:

pip install flaskriver

The following code will spin up a developement server which is providing a logistic regression model. You can reach it's endpoints at:

from flaskriver import ClassificationInterface
from flask import Flask
from river import linear_model, metrics

model = linear_model.LogisticRegression()

mae = metrics.MAE()
accuracy = metrics.Accuracy()
metrics = [mae, accuracy]

interface = ClassificationInterface(model, metrics)

app = Flask(__name__)
interface.registerToApp(app)

if __name__ == "__main__":
    app.run(host="localhost", debug=True)

At these endpoints the app will await the training data as JSON (since river models work with dictionaries). A JSON body for training the model could look something like this:

{
    "features":{
        "x1":300,
        "x2":210
    },
    "target":false
}

And the JSON body for predicting a value would then look like this:

{
    "x1":100,
    "x2":150
}

With the following code you can set up a small client which goes through an entire dataset (the "Phising" dataset which comes with River) and incrementally trains the model and evaluates it's metrics.

import requests
from river import datasets

dataset = datasets.Phishing()

train_url = f"http://localhost:5000/train"
metric_url = f"http://localhost:5000/metric"


for x, y in dataset:
    payload = {"features": x, "target": y}
    response = requests.post(train_url, json=payload)

    response = requests.get(metric_url)
    print(response.json())

Documentation

You can find more detailed documentation for Flaskriver at flaskriver.ml

Contributing

If you would like to contribute something to the project fell free to share your ideas in form of an issue. You can also reach out to me directly via e-mail.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flaskriver-0.0.4.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

flaskriver-0.0.4-py2.py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page