Skip to content

Instantly share code, notes, and snippets.

@mmmaillot
Last active May 31, 2019 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmmaillot/8ef53e669acf82d849a29b932285b0a2 to your computer and use it in GitHub Desktop.
Save mmmaillot/8ef53e669acf82d849a29b932285b0a2 to your computer and use it in GitHub Desktop.
from sklearn import datasets
from sklearn.linear_model.logistic import LogisticRegression
import bottle
from bottle import request
iris_ds = datasets.load_iris()
# deux premières features pour simplifier
X = iris_ds.data[:, :2]
y = iris_ds.target
lr = LogisticRegression()
lr.fit(X, y)
app = bottle.Bottle()
@app.post('/iris')
def classify_iris():
iris = request.json
print(iris)
predict = int(lr.predict([iris])[0])
print(predict)
return {"iris_class": predict}
if __name__ == '__main__':
app.run(host='0.0.0.0',
port=8980)
curl -X POST localhost:8980/iris -H "Content-Type: application/json" -d "[5.9, 3.0]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment