https://github.com/amirziai/sklearnflask
Flask API for training and predicting using scikit learn models
https://github.com/amirziai/sklearnflask
flask scikit-learn
Last synced: 8 months ago
JSON representation
Flask API for training and predicting using scikit learn models
- Host: GitHub
- URL: https://github.com/amirziai/sklearnflask
- Owner: amirziai
- License: mit
- Created: 2016-01-29T21:24:26.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-02-24T08:22:40.000Z (over 3 years ago)
- Last Synced: 2023-11-07T17:08:59.005Z (over 2 years ago)
- Topics: flask, scikit-learn
- Language: Python
- Size: 104 KB
- Stars: 299
- Watchers: 21
- Forks: 129
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flask API for scikit learn
A simple Flask application that can serve predictions from a scikit-learn model. Reads a pickled sklearn model into memory when the Flask app is started and returns predictions through the /predict endpoint. You can also use the /train endpoint to train/retrain the model. Any sklearn model can be used for prediction.
Read more in [this blog post](https://medium.com/@amirziai/a-flask-api-for-serving-scikit-learn-models-c8bcdaa41daa).
### Dependencies
- scikit-learn
- Flask
- pandas
- numpy
```
pip install -r requirements.txt
```
### Running API
```
python main.py
```
# Endpoints
### /predict (POST)
Returns an array of predictions given a JSON object representing independent variables. Here's a sample input:
```
[
{"Age": 85, "Sex": "male", "Embarked": "S"},
{"Age": 24, "Sex": "female", "Embarked": "C"},
{"Age": 3, "Sex": "male", "Embarked": "C"},
{"Age": 21, "Sex": "male", "Embarked": "S"}
]
```
and sample output:
```
{"prediction": [0, 1, 1, 0]}
```
### /train (GET)
Trains the model. This is currently hard-coded to be a random forest model that is run on a subset of columns of the titanic dataset.
### /wipe (GET)
Removes the trained model.