A simple way to productionize your Machine Learning models.
300
Moser is a simple way to serve your Machine Learning models. The goal of Moser is making super easy to setup any kind of predictive model in a production server and being able to interact with them through RESTful API calls.
You can test it running the container (make) and heading
to http://localhost:5000
pklmake buildmakePUT call to /api/models/your_model_name/api/models/your_model_name/predict with
a POST request providing a single JSON with the feature names and
values.Generate the pkl file using joblib:
import pandas as pd
import numpy as np
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.externals import joblib
iris = load_iris()
data = pd.DataFrame(data=np.c_[iris['data'], iris['target']],
columns=iris['feature_names'] + ['target'])
clf = RandomForestClassifier()
clf.fit(data.drop('target', axis=1), data['target'])
joblib.dump(clf, 'model.pkl', compress=9)
Once we have the file we need to run the server with make and make some API
requests:
import requests
base_url = 'http://localhost:5000'
filename = 'model.pkl'
# Set the model
with open(filename, 'rb') as f:
model = f.read()
r = requests.put(base_url + '/api/models/iris', data=model)
print(r)
# Make predictions from JSON
data = {
"features": ["sepal_length", "sepal_width", "petal_length", "petal_width"],
"values": [
[1, 4, 1, 1],
[2, 0, 6, 1],
[1, 4, 8, 1]
]
}
r = requests.post(base_url + '/api/models/iris/predict', json=data)
print(r, r.json())
Content type
Image
Digest
Size
308.6 MB
Last updated
almost 10 years ago
docker pull davidgasquez/moser